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

后端 未结 6 1116
爱一瞬间的悲伤
爱一瞬间的悲伤 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:40

    Here's an improvement on @XGamerX's answer.

    <%= link_to '#', [comment.post, { anchor: dom_id(comment) }] %>
    

    Or

    <%= link_to '#', post_path(comment.post, anchor: dom_id(comment)) %>
    

提交回复
热议问题