简体   繁体   中英

How to make Sign up page be root page in Devise?

I'm running on Rails 4.0.0 with Devise 3.1.0. My routes are setup like this:

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

resources :books

What I'm trying to do is make the Devise Sign Up Page be the Welcome Page for users if they haven't signed in but if their signed in they'll go to the Book Index. Right now it just gives me the standard Ruby on Rails:Welcome Aboard page as if Devise doesn't exist. How would I do this?


Answer

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. Get the root route out of the devise_for block and format it appropriately (as shown in the routes file).
  2. Create a before_filter in your registrations_controller (may need to ovverride the default one devise provides) that checkes if current_user exists and redirects to the books path if it does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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