【发布时间】:2010-08-23 05:16:00
【问题描述】:
单击注销时,我想重定向回用户所在的页面,除非该页面需要用户登录。
场景 1 - “返回”需要用户 1)用户从用户帐户页面单击注销 2) 重定向(最终)到 root_path
场景 2 - “返回”不需要用户 1) 用户从(非用户要求的)事件页面单击注销 2) 重定向(最终)到 events_path
有人建议我更新我的 before_filter :require_use 方法是这样的:
def require_user
unless current_user
flash[:notice] = "You must be logged in to view this page"
redirect_to user_coming_from_logout_method? root_path : login_path
end
end
除非我无法定义#user_coming_from_logout_method?
有人可能会认为它只是:
request.referrer == "/logout"
但在上面的例子中 request.referrer 实际上 == "/user_account",而不是中间的注销方法。很奇怪,我知道。
建议?
【问题讨论】: