Rails 3 - 嵌套资源和会员/收藏
有没有办法避免这样做...
resources :parents do
resources :children do
collection do
get "/search/:term/:offset/:limit.:format", :action => "search", :constraints => { :term => /\w+/, :offset => /\d+/, :limit => /\d+/ }
end
end
end
resources :children do
collection do
get "/search/:term/:offset/:limit.:format", :action => "search", :constraints => { :term => /\w+/, :offset => /\d+/, :limit => /\d+/ }
end
end
我认为可以这样做...
resources :parents do
resources :children do
end
resources :children do
collection do
get "/search/:term/:offset/:limit.:format", :action => "search", :constraints => { :term => /\w+/, :offset => /\d+/, :limit => /\d+/ }
end
end
原因是我希望能够使用这两条路线...
/children/search/term/0/10
/parents/1/children/search/term/0/10
Is there a way to avoid having to do this...
resources :parents do
resources :children do
collection do
get "/search/:term/:offset/:limit.:format", :action => "search", :constraints => { :term => /\w+/, :offset => /\d+/, :limit => /\d+/ }
end
end
end
resources :children do
collection do
get "/search/:term/:offset/:limit.:format", :action => "search", :constraints => { :term => /\w+/, :offset => /\d+/, :limit => /\d+/ }
end
end
I thought it would be possible to just do this...
resources :parents do
resources :children do
end
resources :children do
collection do
get "/search/:term/:offset/:limit.:format", :action => "search", :constraints => { :term => /\w+/, :offset => /\d+/, :limit => /\d+/ }
end
end
The reason being is I want to be able to use both of these routes...
/children/search/term/0/10
/parents/1/children/search/term/0/10
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎可以
如果使用了通过
parent
的路由, 在params
中设置:parent_id
。否则它不会出现。为了清楚起见,我省略了约束。另外,您可能应该将.format
设为可选。This seems to do the trick
:parent_id
will be set inparams
if the route throughparent
has been used. Otherwise it won't be present. I have omitted constraints for clarity. Also you probably should make the.format
optional.