2016-11-11 58 views
1

我有<div id="all-comments">Comments</div>
部分在我的文章显示页面。我在我的帖子索引页上有一个链接,其中显示了评论数量,当点击评论时,我想要转到example.com/posts/1#all-comments
现在我正在使用<%= link_to post_path(@post) %> - 这会生成example.com/posts/1,但我希望#最后的所有评论。Rails转到另一页特别部分

在此先感谢。

回答

0

这在docs for link_to覆盖(虽然有点埋没):

link_to也可以产生与锚或查询字符串链接:

link_to "Comment wall", profile_path(@profile, anchor: "wall") 
# => <a href="/profiles/1#wall">Comment wall</a> 

所以:

<%= link_to post_path(@post, anchor: "all-comments") %> 
相关问题