2016-11-11 6 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") %> 
関連する問題