开发者

Rails 3 Nested resource routes inherits parent constraints, how to avoid it?

开发者 https://www.devze.com 2023-04-10 13:44 出处:网络
It you define constraint on \"id\" in parent resource: resources :fo开发者_开发百科o, constraints: { :id => /CONST/ } do

It you define constraint on "id" in parent resource:

resources :fo开发者_开发百科o, constraints: { :id => /CONST/ } do
  resources :bar
end

The nested resource will inherits that constraint for its own id, thus the generated routes will be like:

/foo/:foo_id/bar/:id/edit(.:format)
{:id=>/CONST/, :foo_id=>/CONST/, :action=>"edit", :controller=>"bar"}

So, I don't want the "id" parameter of Bar resource to be that restricted.

Currently, I've just map the routes I want manually, one by one, but I am really want to generate it by resources helper. How can I do that?


How about :

resources :foo, constraints: { :id => /CONST/ }
resources :foo, constraints: { :foo_id => /CONST/ } do
  resources :bar
end
0

精彩评论

暂无评论...
验证码 换一张
取 消