I have done some research and seen that this question has already been addressed several times, in different places:
- Devise with rails 4 authenticated root route not working
- Different '/' root path for users depending if they are authenticated (using devise)
- Authenticated Route Constraints
- Rails Tip #5: Authenticated Root and Dashboard Routes With Devise
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?