6

如果您在父资源中定义“id”约束:

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

嵌套资源将为其自己的 id 继承该约束,因此生成的路由将如下所示:

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

所以,我不希望 Bar 资源的“id”参数受到限制。

目前,我只是手动一一映射我想要的路线,但我真的很想通过资源助手生成它。我怎样才能做到这一点?

4

1 回答 1

4

怎么样 :

resources :foo, constraints: { :id => /CONST/ }
resources :foo, constraints: { :foo_id => /CONST/ } do
  resources :bar
end
于 2011-10-03T14:34:10.627 回答