Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link_to div with Ruby on Rails

How would i use

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

to link to a div, for example the url:

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

i need to do this so that when a user clicks the comments link they are taken to the comments div on the page. This would also be useful to use to redirect users to the comment they have just posted like so:

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

thanks alot!

like image 939
Alex Avatar asked Jul 13 '10 15:07

Alex


2 Answers

You can use:

<% link_to(post, :anchor => 'mydiv') do %> 
   <%= pluralize(post.comments.size,'comment') %> 
<% end %>
  • link_to API documentation
like image 68
John Topley Avatar answered Nov 01 '22 20:11

John Topley


link_to(post, pluralize(post.comments.size,'comment'), :anchor => "mydiv")
like image 26
robertokl Avatar answered Nov 01 '22 21:11

robertokl