Ruby on rails application root

2019-06-21 12:29发布

问题:

How do I change a rails app so that a controller foo appears as the application root?

In other words, right now all the urls look like host.com/foo/... and I'd like to get rid of the foo and have simply host.com/...

回答1:

In routes.rb, add:

map.root :controller => 'foo'

Full details in the API.



回答2:

In your routes.rb you add a named route like so:

map.home '', :controller => 'foo', :action => 'index'

This will build a route for when the root of web application is requested, it will use the foo controller and call the index action. Make sure you have it at the bottom so it is given the lowest priority.