2010-09-17 57 views
0

我想改变的回报率,以我想要的默认路由: 考虑下面的例子...问题航线

:controller/:action/:id 

,这将给你的路线在浏览器中: http://localhost:3000/controller/action/id

现在我想将它更改为...

http://localhost:3000/this-is-what-i-want/id

我们可以得到控制和操作的别名,以及喜欢...

resources :controller, :as => "my-custom-name" 

,如果你想为行动别名,然后

resources :controller, :path_names => { :action => 'my-custome-name-1', :action => 'my-custome-name-2' } 

BUT我想改变控制器和动作立即...如果你注意到上述http://localhost:3000/this-is-what-i-want/id路径的问题...

需要帮助...提前 感谢...

回答

1

您需要命名路线。

在Rails2:

map.a_name 'this-is-what-i-want/:id', :controller => 'controller_name', :action => 'action_name' 

在Rails3中:

match 'this-is-what-i-want/:id' => 'controller_name#action_name' 
+0

现在如果我想:map.a_name '这 - ,是什么,我想做/动态名称/:身份证' ,:controller =>'controller_name',:action =>'action_name'...我如何在rails中为“动态名称”设置链接......? – 2010-09-17 14:12:10

+0

然后按照Jesse Wolgamott的建议使用休息路线 – Yannis 2010-09-17 20:59:09

0

你想使用休息的路线,而不是控制器/动作

我将使用“球”,而不是“这-is-什么,我想做”

resources :balls 

然后,当你链接到一个球,做link_to(ball.name, ball)。

这会给你的http://localhost:3000/balls/45

rails rest cheatsheet的链接是一个好的开始。