41

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?

1 Answer 1

86

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.

1
  • the before action may exist in an inherited controller. is there a way to exclude the controller not the action in the parent controller? Feb 17, 2022 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.