Rails 3 嵌套资源路由继承父级约束,如何避免?
如果您在父资源中定义对“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”参数是这样的受限制的。
目前,我只是手动一一映射我想要的路线,但我真的想通过资源助手生成它。我怎样才能做到这一点?
It you define constraint on "id" in parent resource:
resources :foo, 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样:
How about :