[英]Rails 4 + Devise: set default root route for authenticated users
I have done some research and seen that this question has already been addressed several times, in different places: 我进行了一些研究,发现这个问题已经在不同的地方被解决过几次了:
I tried to follow the examples given in the links above and came up with the following solution, in my routes.rb
file: 我尝试遵循上面链接中给出的示例,并在
routes.rb
文件中提出了以下解决方案:
root to: 'pages#home'
devise_for :users, :path => 'account', controllers: { registrations: "registrations", confirmations: "confirmations" }
authenticated :user do
root 'calendars#index', as: :authenticated_root
end
The goal here is to direct unauthenticated
users to the regular home
page of the website, while authenticated
users will go to their dashboard, inside the app, ie the calendars#index
route, defined as follows in my routes: 此处的目标是将
unauthenticated
authenticated
用户定向到网站的常规home
,而经过authenticated
用户将进入其在应用程序内的仪表板,即calendars#index
路由,在我的路由中定义如下:
calendars GET /calendars(.:format) calendars#index
However, when I log in as a user, and visit http://localhost:3000/
, I keep landing on the regular home
page of the website, instead of the user's dashboard inside the app. 但是,当我以用户身份登录并访问
http://localhost:3000/
,我会继续登陆网站的常规home
,而不是应用程序内用户的仪表板。
What am I doing wrong? 我究竟做错了什么?
Change routes.rb
so that the unauthenticated root
route is wrapped, just like the authenticated one: 更改
routes.rb
以便包装未经身份验证的root
路由,就像经过身份验证的root
路由一样:
devise_for :users, :path => 'account', controllers: { registrations: "registrations", confirmations: "confirmations" }
authenticated :user do
root 'calendars#index', as: :authenticated_root
end
unauthenticated :user do
root 'pages#home', as: :unauthenticated_root
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.