Search code examples
ruby-on-railsactioncontroller

Do before_filter :except work across subclass controller?


I want to declare some methods from a different controller in ApplicationController's filter like below:

In ApplicationContoller

before_filter :authorize, :except => [:index, :show, :different_controller_method]

where :different_controller_method is defined in UserController. Can we do this?


Solution

  • Normally this should work. Make sure you are using symbols, as @jdl is saying.

    Most of the times we use a different approach though. In your ApplicationController you write

    before_filter :authorize
    

    So that by definition all access is authorized. In your UsersController you can then add an exception:

    skip_before_filter :authorize, :only => [:index, :show, :different_controller_method]
    

    Hope this helps.