如何使注册页面成为Devise的根页面?

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

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

我想要做的是让Devise注册页面成为用户的欢迎页面,如果他们还没有登录,但是如果他们已登录他们将进入图书索引。 现在它只是给我标准的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 

 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 
  1. 从devise_for块中获取根路由并对其进行适当格式化(如路径文件中所示)。
  2. 在registrations_controller中创建一个before_filter(可能需要ovverride默认的一个设备提供),检查current_user是否存在,如果存在则重定向到books路径。