简体   繁体   中英

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

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

Thanks in advance

You can write singular route like as follow. You will get record id in params[:id] in controller action.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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