登录用户和未登录用户的不同页面 [英] Different page for logged in user and not logged in user at root
本文介绍了登录用户和未登录用户的不同页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Rails 中为用户显示不同的根页面.
I want to show different root page for users in Rails.
我定义了根:
root :to => 'welcome#index'
还有欢迎控件:
class WelcomeController < ApplicationController
before_filter :authenticate_user!
def index
end
end
目前登录用户可以,但未登录用户重定向到/users/sign_in
Currently it is ok for logged in users, but the not logged in users redirected to /users/sign_in
我想显示静态根页面而不是重定向.
I want to show static root page and not redirect.
推荐答案
Puneet Goyal 建议的答案在 Rails 4 中不起作用.请参阅 这个.解决方案是为两条路由之一使用别名,如下所示:
The answer, suggested by Puneet Goyal will not work in Rails 4. See this. The solution is to use an alias for one of the two routes like this:
authenticated do
root :to => 'welcome#index', as: :authenticated
end
root :to => 'home#static_page'
这篇关于登录用户和未登录用户的不同页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文