我有嵌套资源:
resources :posts do
resources :comments
end
我当前的link_to
是这样的:
<%= link_to 'Reply', [:new, @post, :comment] %>
导致:
http://example.com/posts/8/comments/new
但我需要这样的链接:
http://example.com/posts/8/comments/new?parent_id=7
如何使用link_to
创建该链接?
答案 0 :(得分:1)
我能用一个匹配声明得到它:
match "(/bazess/:baz_id)(/foos/:foo_id)/bars(/page/:page)(/:format)" => "bars#index", :as => :bars
您也可以参考this article on nested resources from The Rails 3 Way。
答案 1 :(得分:1)
在我发表评论后发表回答:
new_post_comment_path(@post, :parent_id => 7)