我有一个Rails 3应用程序。
当用户未登录时...我想设计显示非签约页面: SignIn,注册,关于我们,博客等…
当用户登录时,我希望它转到web应用程序
我在哪里做这个开关,我如何设置它?谢谢
发布于 2010-10-22 10:16:51
这很简单!我刚刚用devise完成了一个Rails 3应用程序,所以我的痛苦可以成为你的收获。只需在要保护的控制器的开头包含before_filter即可。让我们以一个视频控制器为例:
class VideosController < ApplicationController
before_filter :authenticate_user!
# all your actions go here: index, new, create, etc #
end您还可以选择过滤控制器中的哪些动作:
class VideosController < ApplicationController
before_filter :authenticate_user!, :only => [:edit, :update, :destroy]
# all your actions go here: index, new, create, etc #
endDevise为您提供了authenticate_user!方法,并为您重定向。
https://stackoverflow.com/questions/3993398
复制相似问题