How to create an anchor and redirect to this specific anchor in Ruby on Rails

后端 未结 6 1111
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 17:04

I\'m trying to create unique anchors for every comment on my blog so a person can take the url of an anchor and paste it in their browser, which will automatically load the

6条回答
  •  伪装坚强ぢ
    2020-12-05 17:58

    Actually, anchor is an option for the path, not for the link_to

    <%= link_to '#', post_path(comment.post, :anchor => "comment_#{comment.id}") %>
    

    http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001565

    link_to "Comment wall", profile_path(@profile, :anchor => "wall")
           # => Comment wall
    

提交回复
热议问题