开发者

link_to div with Ruby on Rails

开发者 https://www.devze.com 2023-01-07 16:09 出处:网络
How would i use <% link_to (post) do %> <%= pluralize(post.comments.size,\'comment\') %> <% end %>

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!


You can use:

<% link_to(post, :anchor => 'mydiv') do %> 
   <%= pluralize(post.comments.size,'comment') %> 
<% end %>
  • link_to API documentation


link_to(post, pluralize(post.comments.size,'comment'), :anchor => "mydiv")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号