简体   繁体   English

Ruby on Rails 路由能否在单个操作中指向嵌套 URL?

[英]Can Ruby on Rails Routes point a nested URL at a single action?

Is it possible in Ruby on Rails (we're using v2 still) to allow the routes file to map a nested url EG是否可以在 Ruby on Rails(我们仍在使用 v2)中允许路由文件映射嵌套的 url EG

mydomain.com/controller/object/action mydomain.com/controller/object/action

to a single action eg单个动作,例如

:controller, :action :控制器, :动作

? ?

We currently have a url like mydomain.com/controller/action and i want to change it to mydomain.com/controller/object/action我们目前有一个类似 mydomain.com/controller/action 的网址,我想将其更改为 mydomain.com/controller/object/action

Thanks in advance提前致谢

You can write singular route like as follow.您可以编写如下所示的单一路线。 You will get record id in params[:id] in controller action.您将在控制器操作中的 params[:id] 中获得记录 ID。

match 'controller/:id/action' => 'controller#action', via: :get

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM