2

I have done some research and seen that this question has already been addressed several times, in different places:

I tried to follow the examples given in the links above and came up with the following solution, in my routes.rb file:

root to: 'pages#home'

devise_for :users, :path => 'account', controllers: { registrations: "registrations", confirmations: "confirmations" }

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

The goal here is to direct unauthenticated users to the regular home page of the website, while authenticated users will go to their dashboard, inside the app, i.e. the calendars#index route, defined as follows in my routes:

calendars GET    /calendars(.:format)                        calendars#index

However, when I log in as a user, and visit http://localhost:3000/, I keep landing on the regular home page of the website, instead of the user's dashboard inside the app.

What am I doing wrong?

Community
  • 1
  • 1
Thibaud Clement
  • 6,607
  • 10
  • 50
  • 103

1 Answers1

5

Change routes.rb so that the unauthenticated root route is wrapped, just like the authenticated one:

devise_for :users, :path => 'account', controllers: { registrations: "registrations", confirmations: "confirmations" }

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

unauthenticated :user do
  root 'pages#home', as: :unauthenticated_root
end
steve klein
  • 2,566
  • 1
  • 14
  • 27