【发布时间】:2015-12-01 04:12:38
【问题描述】:
我做了一些研究,发现这个问题已经在不同的地方多次解决:
- Devise with rails 4 authenticated root route not working
- Different '/' root path for users depending if they are authenticated (using devise)
- Authenticated Route Constraints
- Rails Tip #5: Authenticated Root and Dashboard Routes With Devise
我尝试按照上面链接中给出的示例,并在我的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用户引导到网站的常规home页面,而authenticated用户将转到他们的仪表板,在应用程序内部,即calendars#index路由,定义如下我的路线:
calendars GET /calendars(.:format) calendars#index
但是,当我以用户身份登录并访问 http://localhost:3000/ 时,我一直登陆网站的常规 home 页面,而不是应用内的用户仪表板。
我做错了什么?
【问题讨论】:
-
在您包含的第一个链接中,我会尝试包装未经身份验证的
root路由。 -
谢谢,确实有效。随时提交此作为答案,我将非常乐意接受。
标签: ruby-on-rails ruby-on-rails-4 authentication devise rails-routing