Exclude controller from before_action

I use the before_action filter to call authenticate , which is a method that redirects users to their home page if they are not authorized on the requested page.

I would like to exclude the page from this step, for testing purposes only.

What I have seen so far is that I can use except to exclude certain controller actions from the before_action filter, for example:

 before_action :authenticate, except: :demo_login 

I can also exclude more than one action in this time:

 before_action :authenticate, except [:demo_login, :demo_show] 

How can I exclude all actions in a specific controller?

+6
source share
1 answer

Use skip_before_action :authenticate in the appropriate controller.

The format of this method is the same as before_action , so if you want to skip the :authenticate call for a specific controller action, use:

skip_before_action :authenticate, only: [:show, :index]

You can also use the except: keyword.

+13
source

All Articles