Reputation: 994
I'm trying to redirect my www.example-app.com
root to www.example-app.com/app/dashboard
using routes.rb
. At the moment i'm doing it like so:
root to: redirect('/app/dashboard')
But would like to do that using named route, for example:
get 'app/dashboard' => 'accounts#dashboard', as: :account_dashboard
But when i put that in routes:
root to: redirect(account_dashboard_url)
... of course it doesn't work, how can i do it?
Upvotes: 8
Views: 7387
Reputation: 3454
Please note, that as of Rails 5, redirecting from the routes is possible.
match "*", to: redirect('/something-else'), via: :all
http://guides.rubyonrails.org/routing.html#redirection
This page is quite high on some Google-keywords, and this might be misleading.
Upvotes: 1
Reputation: 313
You can't do this directly in routes.rb (as of now – Rails 4.2), but there are ways to make it work. The simplest, IMO, would be to create a method in your application controller to do the redirection.
# routes.rb
root to: 'application#redirect_to_account_dashboard'
and
# application_controller.rb
def redirect_to_account_dashboard
redirect_to account_dashboard_url
end
Upvotes: 6