简体   繁体   中英

Rails 4, Route with multiple ids

I want to make a route like this /p/:id/:ph_id . and the :ph_id also has limitation on length /\\d{7}/

This is what I have for the first id

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

In your config/routes.rb try following code:

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!

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