Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling before_filter only for specific controllers

I have a few controllers which are used for specific purposes and each have a "def index" function. Like /index uses the home page and calls the unauthenticated home page. /jobs/index is another and /users/index is another. Each of them are using different controllers like JobsController, HomeController, UsersController.

My ApplicationController has a before_Filter

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

The problem with this is that this will also skip when I call /jobs/index or /users/index (or any other /*/index page for that matter). Is there a way so that I can apply the "/except" clause only to "home#index" request (ie HomeController -> index page). I tried,

before_filter :authenticate_user!, :except => ["home#index"] but it doesn't work.
like image 922
Rajat Avatar asked Sep 27 '12 17:09

Rajat


1 Answers

You can use

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

in your home_controller for skipping the before_filter for that action...

like image 150
Rahul garg Avatar answered Nov 18 '22 04:11

Rahul garg