My Rails 3.1 app has two user models: User and Admin. I’m using Devise.
My routes.rb contains
root :to => "pages#welcome"
where users can login as a User or and Admin.
Once logged in, the root path should change. The root for Admins should be “admins#dashboard”, the root for Users should be the current user’s show page.
I’m having trouble working out how best to achieve this, and I have three questions.
- How do I define resource specific roots. I feel that I should be
defining a ‘user_root_path’ and an “admin_root_path’ but haven’t been able to work out the
syntax for this in my routes file? - How to I pass in the current user’s ID so that I can root to the user’s show page?
- How can I ensure that only a User or an Admin session can be active at any one
time, and that users cannot login as both simultaneously?
I would be very grateful for a pointer in the right direction, as this has got me stumped!
Thank you.
After a bit of digging, and some pointers from Mikhail, I managed to answer this myself.
In my routes.rb file I added the following:
to define the root for unauthenticated users.
to define the root for authenticated admins, and
to define the admin after login redirect and tidy up the path.
Thanks for all the repsonses!