开发者

before_filter with another controller

I am trying to create an action th开发者_StackOverflow社区at will check for every page if the user is logged in. For that, in the controller Home I created this method:

def check_session
  if !session[:user_id]
    redirect_to :action=> 'login'
  end
end

And I've put this code at the head of the controller:

before_filter :check_session, :except => [:sub_layout, :authenticate, :login]

Now I want to use check_session from outside the pages of Home, lets say in the pages of Users. What is the correct syntax for calling a method of a different controller in the before_filter?


If you move everything you already have to the application_controller it will check for every controller in your app. Then use the :skip_before_filter method to bypass the check for whatever controllers/actions you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜