Search code examples
ruby-on-railsrubydeviseruby-on-rails-4

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

Solution

  • 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