Skip to content

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

Clay Shentrup edited this page Oct 10, 2020 · 2 revisions

This works in Rails 5.1+

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.

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
Clone this wiki locally