E
E
eldar_web2016-01-26 17:55:43
Ruby on Rails
eldar_web, 2016-01-26 17:55:43

How to exclude a specific controller method in before_filter in Ruby on Rails?

Let's say there is a uses/new method, in routes there is also an alias 'registration' => 'users#new'.
So I write:
before_filter :authorize, :except => ['user/new']

before_filter :authorize, :except => ['registartion']
--- does not work.
But if you write :new, but you don't need to do that, because other controllers also have new.
How can the problem be solved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Mitrushchenkov, 2016-01-26
@eldar_web

Hello, I think this is what you need. Use skip_before_action in the controller you need.

E
Evgeniy Trebin, 2016-01-26
@evgeniy_trebin

before_action only: :new do |controller|
    authenticate unless controller.class.name == 'UsersController'
end

something like that, but it's better to think about the architecture

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question