简体   繁体   中英

Rails dynamic routes with url helper methods

Say I have a routes setup like this

scope"(foo/:user_id/)" do
  resources :bar
end

Can I still use URL helper methods to generat my URLs (without having to write my own)?

What would the url helper method look like to get the url /foo/1234/bar/new

Try using, for example, bar_path(:user_id => 1, :id => 2) to get /foo/1/bar/2 .

Btw, why do you need these parenthesis in the scope? I think it should be just like that:

scope "foo/:user_id/" do
  resources :bar
end

Shouldn't it?

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