[英]Different page for logged in user and not logged in user at root
I want to show different root page for users in Rails. 我想在Rails中为用户显示不同的根页面。
I defined the root: 我定义了根:
root :to => 'welcome#index'
And the welcome control: 和欢迎控件:
class WelcomeController < ApplicationController
before_filter :authenticate_user!
def index
end
end
Currently it is ok for logged in users, but the not logged in users redirected to /users/sign_in 目前,登录用户可以,但未登录的用户重定向到/ users / sign_in
I want to show static root page and not redirect. 我想显示静态根页面而不重定向。
In your routes.rb
: 在您的
routes.rb
:
authenticated do
root :to => 'welcome#index'
end
root :to => 'home#static_page'
This will ensure that root_url
for all authenticated users is welcome#index
这将确保
welcome#index
所有通过身份验证的用户使用root_url
For your reference: https://github.com/plataformatec/devise/pull/1147 供您参考: https : //github.com/plataformatec/devise/pull/1147
This answer should work. 这个答案应该起作用。 This was posted on the page Bradley linked.
这被张贴在Bradley链接的页面上。
Put this in your Welcome controller. 将其放在您的Welcome控制器中。
def index
if authenticate_user?
redirect_to :controller=>'dashboard', :action => 'index'
else
redirect_to '/public/example_html_file.html'
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.