Link_to div with Ruby on Rails

How to use

<% link_to (post) do %>
   <%= pluralize(post.comments.size,'comment') %>
<% end %>   

for a div reference, for example url:

http://myblog.com/post/21#mydiv

I need to do this so that when the user clicks the link for comments, they go to the comment div on the page. It would also be useful to redirect users to the comment they just posted:

http://myblog.com/post/21#comment_id

Thank you so much!

+5
source share
2 answers

You can use:

<% link_to(post, :anchor => 'mydiv') do %> 
   <%= pluralize(post.comments.size,'comment') %> 
<% end %>
+6
source
link_to(post, pluralize(post.comments.size,'comment'), :anchor => "mydiv")
+2
source

All Articles