I am using Rails 3 and Devise to create an app where users arrive to the website and are shown a homepage containing a login and a signup form. This page has its own controller ("homepage") so it's route is
root :to => "homepage#index"
I want to display a different homepage if the users are already logged in. This would account to having the root point to
root :to => "dashboard#index"
Is there a way to have a conditional route in routes.rb, that would allow me to check whether the user is authenticated before routing them to one of those homepages?
I tried using the following code but if I'm not logged in, devise asks me to log in, so clearly only the first route works.
authenticate :user do
root :to => "dashboard#index"
end
root :to => "homepage#index"
Also, I want the url to point to www.example.com in both cases, so that www.example.com/dashboard/index and www.example.com/homepage/index never appear in the browser.
Thanks a million !!!
Try this, it's specific to Warden/Devise though.
root to: "dashboard#index", constraints: lambda { |r| r.env["warden"].authenticate? }
root to: "homepage#index"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With