Rails 3:将资源路由到另一个名称 [英] Rails 3 : route a resource to another name

查看:74
本文介绍了Rails 3:将资源路由到另一个名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于模型的CRUD控制器。

I have a CRUD controller for a model.

resources:foo 允许我在 / foo /:id 等用于调用操作。

Doing resources :foo allows me to route on /foo/:id, etc. for calling actions.

我想添加一条路线来翻译'foo 的另一种语言。假设说 toto。
因此,我希望所有 / toto /:id 等路线完全像 / foo /:id 等路线。

I want add a route for a translation of 'foo' in another language. Let's say 'toto'. So I want all the /toto/:id, etc., routes to act exactly like the /foo/:id, etc., routes.

我该如何实现?

推荐答案

您可以添加一个新资源并将foo指定为控制器:

You can add a new resource and specify foo as the controller:

resources :toto, :controller=>"foo"

这会将所有操作都指向 foo,但是有一个知道了。如果您使用的是foo_url或类似的名称,我认为您会在页面上的链接上遇到问题。因此,您将不得不找出一种基于 request.path中的控制器动态创建URL的方法。

This will point all the actions to "foo", but there is a gotcha. I think you will run into problems with the links on the page, if you are using foo_url or something like that. So you would have to figure out a way to create the URLs dymanically based on the controller in "request.path".

这篇关于Rails 3:将资源路由到另一个名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆