Question: 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.

1. 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?
2. How to I pass in the current user's ID so that I can root to the user's show page?
3. 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.

Answer: 
You can use namespace for Admin users => 2 different roots.
Also take a look at the devise configuration file `devise.rb` it has some settings for managing scopes( User and Admin ). For example:

```
 # ==> Scopes configuration
  # Turn scoped views on. Before rendering "sessions/new", it will first check for
  # "users/sessions/new". It's turned off by default because it's slower if you
  # are using only default views.
  # config.scoped_views = false

  # Configure the default scope given to Warden. By default it's the first
  # devise role declared in your routes (usually :user).
  # config.default_scope = :user

  # Configure sign_out behavior.
  # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
  # The default is true, which means any logout action will sign out all active scopes.
  # config.sign_out_all_scopes = true

```

If you not familiar with namespaces, you can read about them [here](http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing)
pages#welcome<--- in this controller and action send params anonymous

Could you please try this in your application.rb

```
def after_sign_in_path_for(resource)
  if params[:anonymous].eql?("1") // mean user
    redirect_to user_root_path, :user_id => current_user.id
  else // mean administration
    redirect_to admin_root_path
  end
end

```

config user\_root\_path and admin\_root\_path to your destination you want in route.rb

Hope it will help.