我有一个问题有点奇怪:我想限制只有非登录用户访问页面。
我应该这样做:
class StaticPagesController < ApplicationController
def globalpresence
redirect_to root_path if user_signed_in?
end
end
这是正确的方法吗? 使用Rails或设计是否有更清洁/更正确的方法?
由于
答案 0 :(得分:1)
从长远来看,过滤器可能会更灵活
before_filter :only_allow_guest_users, only: :global presence
def globalpresence
end
def only_allow_guest_users
redirect_to root_path if user_signed_in?
end