2016-11-11 45 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") %> 
相關問題