Back to Devise Wiki

How To: Define A Different Root Route For Logged Out Users

How-To:-Define-a-different-root-route-for-logged-out-users.md

latest493 B
Original Source

This works in Rails 5.1+

ruby
Rails.application.routes.draw do
  devise_for :users

  authenticated :user do
    root 'secret#index', as: :authenticated_root
  end

  root "home#index"
end

For Rails 6, you must use unauthenticated and it must come before the authenticated block.

ruby
Rails.application.routes.draw do
  devise_for :users

  unauthenticated do
    root "home#index"
  end

  authenticated :user do
    root 'secret#index', as: :authenticated_root
  end
end