Redirect root to named route in rails 4
redirect, routes, ruby-on-rails-4
Solution
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
Problem
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?