我正在使用一个数组为我的 rails link_to 标签生成路径,但似乎无法弄清楚如何添加锚选项。这是我的 link_to 标签:
<%= link_to pluralize(post.comments.count, 'comment'), [post.postable, post] %>
<%= link_to "Leave a comment", [post.postable, post] %>
由于我对帖子使用多态关联(并且它们是嵌套路由),因此我不能简单地使用由 routes.rb 文件中的资源助手生成的路径。
以前,我能够在自动生成的路径上使用锚选项,因为我没有使用与此模型的多态关联。这就是它的样子:
<%= link_to pluralize(post.comments.count, 'comment'), project_post_path(@project, post, {anchor: 'comments'}) %>
<%= link_to "Leave a comment", project_post_path(@project, post, {anchor: 'new-comment'}) %>
关于在使用数组生成 url 时如何将锚标记返回到 link_to 标记的任何提示?提前致谢。