Call before_filter for specific controllers only

I have several controllers that are used for specific purposes, and each has a def def function. Like / index uses a homepage and calls an unauthenticated homepage. / jobs / index is different, and / users / index is different. Each of them uses different controllers, such as JobsController, HomeController, UsersController.

My ApplicationController has before_Filter

before_filter :authenticate_user!, :except => [:index] 

The problem is that this will also be skipped when I call / jobs / index or / users / index (or any other / * / index page, for that matter). Is there a way so that I can only apply the "/ except" clause to the query "home # index" (for example, HomeController → index page). I tried,

 before_filter :authenticate_user!, :except => ["home#index"] but it doesn't work. 
+7
source share
1 answer

you can use

 skip_before_filter :authenticate_user! , :only => [:index] 

in your home_controller to skip the before_filter file for this action ...

+18
source

All Articles