简体   繁体   English

Rails 4,路由多个ID

[英]Rails 4, Route with multiple ids

I want to make a route like this /p/:id/:ph_id . 我想做一个这样的路线/p/:id/:ph_id and the :ph_id also has limitation on length /\\d{7}/ 并且:ph_id也有长度限制/\\d{7}/

This is what I have for the first id 这就是我对第一个id的看法

 scope '/p', :controller => 'people' do
   scope '/:id', :id => /\d{7}/ do end
 end

In your config/routes.rb try following code: 在你的config/routes.rb尝试以下代码:

get "/p/:id/:ph_id" => "people#show", as: :my_route, id: /\d{7}/, ph_id: /\d{7}/

You can use it like: 您可以像以下一样使用它:

<%= link_to "Check this link!", my_route_path(id: 1234567, ph_id: 7654321) %>

Hope that helps! 希望有所帮助! Good Luck! 祝好运!

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

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