18

我正在使用 Devise 3.1.0 在 Rails 4.0.0 上运行。我的路线设置如下:

devise_for :users do
  root "devise/registrations#new"
end

resources :books

我想要做的是让 Devise Sign Up Page 成为用户的欢迎页面,如果他们没有登录,但如果他们登录了,他们会去 Book Index。现在它只是给了我标准的 Ruby on Rails:Welcome Aboard 页面,就好像 Devise 不存在一样。我该怎么做?


回答

https://github.com/plataformatec/devise/issues/2393

devise_for :users
devise_scope :user do
  authenticated :user do
    root :to => 'books#index', as: :authenticated_root
  end
  unauthenticated :user do
    root :to => 'devise/registrations#new', as: :unauthenticated_root
  end
end
4

2 回答 2

34
devise_for :users
devise_scope :user do
  authenticated :user do
    root to: 'books#index'
  end
  unauthenticated :user do
    root to: 'devise/registrations#new', as: :unauthenticated_root
  end
end
于 2013-09-19T20:35:09.163 回答
0
  1. 从 devise_for 块中获取根路由并对其进行适当的格式化(如路由文件中所示)。
  2. 在您的registrations_controller 中创建一个before_filter(可能需要覆盖一个设计提供的默认值),检查current_user 是否存在,如果存在则重定向到books 路径。
于 2013-09-19T19:24:26.113 回答