Search code examples
ruby-on-railsroutescontrollers

rails Do not call before_filter for a specific URL


I am defining a before_filter :authorize_special_user, which checks if the special condition exists or not. If yes, then it is okay, otherwise I redirect to a URL like "/users/special#account". So how do I specify the before_filter to NOT be called on the URL "/users/special#account"? Normally it is done by

before_filter :authorize_special_users :except => [ :users ]

But it will not work here. I tried

before_filter :authorize_special_users :except => [ "/users/special#account" ]

but it does not work either.


Solution

  • An alternative solution would be to wrap the code inside the before filter in a conditional:

    def authorize_special_users
        unless request.path == "/users/special"
            ...
        end
    end