Ruby on rails application root

五迷三道 提交于 2019-12-23 10:15:20

问题


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.



来源:https://stackoverflow.com/questions/472020/ruby-on-rails-application-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!