如何在Rails中将多个参数传递给嵌套路径路径?

我是Rails的新手,通常为正常的unnested路由设置一个link_to帮助器,如下所示:

 link_to "Delete", article_path(article.id), method: :delete, data: {confirm: "Are you sure?"} 

但是我正在学习嵌套路由,似乎我需要提供带有两个参数的路径,例如:

 link_to "(Delete)", article_comments_path(comment.article_id, comment.id), method: :delete, data:{comfirm: 'Are you sure?'} 

然而,这似乎不起作用。 我已经看到你可以像这样格式化link_to

 link_to 'Destroy Comment', [comment.article, comment], method: :delete, data: { confirm: 'Are you sure?' } 

但这似乎让我感到困惑,因为没有定义路径,路径所需的值也没有直接指定。

是否可以格式化嵌套的link_to路径,如上面的unnested路径,还是需要格式化,如第三个例子所示? 如果是这样,有人可以尝试解释如何将此数组格式转换为Rails执行的URL?

谢谢

路线:

article_comment_path – DELETE – /articles/:article_id/comments/:id(.:format) – 评论#stroy

我认为你的路线类似于articles/:article_id/comments/:id所以你可以这样做:

 <%= link_to "Delete", article_comments_path(article_id: comment.article_id, id: comment.id), method: :delete, data:{comfirm: 'Are you sure?'} %> 

你的第三个链接应该是

 <%= link_to 'Destroy Comment', polymorphic_path(comment.article, comment), method: :delete, data: { confirm: 'Are you sure?' } %> 

有关详细信息,请检查Polymorphic routes

更新

你只需要将本地人传递给你的部分:

 <%= render "comment", locals: {article: comment.article, comment: comment} %> 

然后使用

 <%= link_to "Delete", article_comments_path(article.id,comment.id), method: :delete, data:{comfirm: 'Are you sure?'}%>