开发者

Rails Route question

开发者 https://www.devze.com 2022-12-21 18:04 出处:网络
I want to setup a route so that if the user goes to http://mysite.com/page.html it is routed to the controller page开发者_运维知识库_controller and the action index.How would I do this?You can do this

I want to setup a route so that if the user goes to http://mysite.com/page.html it is routed to the controller page开发者_运维知识库_controller and the action index. How would I do this?


You can do this using a named route:

map.page '/page.html', :controller => 'page'


The usual setup would be to use ressource mapping for this by adding the following line to routes.rb

map.resources :pages

However that will link to http://mysite.com/pages.html and use pages_controller (notice the plural!). But you should be using plurals anyway if you want to stick to the standard Rails way.

0

精彩评论

暂无评论...
验证码 换一张
取 消