Devise logged in root route rails 3 Devise logged in root route rails 3 ruby ruby

Devise logged in root route rails 3


Think you may have been looking for this:

authenticated :user do  root :to => "dashboard#show"endroot :to => "devise/sessions#new"

Note: it's authenticate*d*


I too wanted this in my app, here's what I came up with.

MyCoolioApp::Application.routes.draw do  root :to => 'users#dashboard', :constraints => lambda {|r| r.env["warden"].authenticate? }  root :to => 'welcome#index'  get "/" => 'users#dashboard', :as => "user_root"  # ..end

In Rails 3 you can use Request Based Contraints to dynamically map your root route. The solution above works for the Devise authentication gem but can be modified to support your own implementation.

With the above root_path or / will route to a WelcomeController#index action for un-authenticated requests. When a user is logged in the same root_path will route to UsersController#dashboard.

Hope this helps.


I have the same problem and I solved it with this:

authenticated :user do  root :to => "wathever#index"endunauthenticated :user do  devise_scope :user do     get "/" => "devise/sessions#new"  endend

Hope it helps.