Search code examples
ruby-on-railsruby-on-rails-4before-filter

before_filter in few controllers


I would like use one before_filter named :realtor_suscriber in few specific actions in the following controllers :

realtors/registrations_controller.rb
realtors/sessons_controller.rb
pro/messages_controller.rb
pro/users_controller.rb

I defined realtor_suscriber like that in realtors/registrations_controller.rb

def realtor_suscriber!
....my code here...
end

Of course, it doesnt work with action in other controllers (for example pro/messages_controller.rb)

I dont want define realtor_suscriber in application_controller.rb because i've some other controllers they doesnt need this before_filter and i would like avoid to use skip_before_filter in all the other controllers.

Thanks for advance,

F.


Solution

  • You can define the realtor_suscriber! method in ApplicationController and add

    before_filter :realtor_suscriber!
    

    in those controllers, where you need it.