繁体   English   中英

Rails 4 + Devise:为经过身份验证的用户设置默认的根路由

[英]Rails 4 + Devise: set default root route for authenticated users

我进行了一些研究,发现这个问题已经在不同的地方被解决过几次了:

我尝试遵循上面链接中给出的示例,并在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

此处的目标是将unauthenticated authenticated用户定向到网站的常规home ,而经过authenticated用户将进入其在应用程序内的仪表板,即calendars#index路由,在我的路由中定义如下:

calendars GET    /calendars(.:format)                        calendars#index

但是,当我以用户身份登录并访问http://localhost:3000/ ,我会继续登陆网站的常规home ,而不是应用程序内用户的仪表板。

我究竟做错了什么?

更改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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM