Check if current controller has parent of some other controller inside the application_controller
-
25-09-2019 - |
Question
I have a separete part of the site for separate, dedicated customers, they have tools under /dedicated path, and all controllers they have are inheritences of DedicatedController. I want to create a before_filter in application_controller to protect this customers from opening any other pages that are not in controllers that inherited by dedicated_controlle.
Solution
If you use a before_filter
in the ApplicationController to prevent customers from going to pages there you can use skip_filter
in the base controller for the DedicatedController.
So for ours we have:
class ApplicationController
before_filter :ensure_not_a_customer
.
.
end
class Admin::BaseController < ApplicationController
skip_filter :ensure_not_a_customer
.
.
end
class Admin::WebpageController < Admin::BaseController
.
.
end
Then anything inherited from Admin::BaseController will skip the before_filter from the ApplicationController.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow