Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude a controller from before_action

I am using the before_action filter to call authenticate which is a method that will redirect users back to their home page if they aren't authorized to be on the page requested.

I would like to exclude a page from this step, just for testing purposes.

What I have seen so far is that I can use except to exclude certain controller actions from being subject to the before_action filter so like:

before_action :authenticate, except: :demo_login 

I can also exclude more than one action at a time like this:

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

How can I exclude all actions in a specific controller?

like image 791
Matt C Avatar asked Apr 27 '16 00:04

Matt C


1 Answers

Use skip_before_action :authenticate in the relevant controller.

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

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

The except: keyword can also be used.

like image 200
Anthony E Avatar answered Sep 22 '22 23:09

Anthony E