0

I having trouble with an Ajax response in Rails and I don't know how to go about debugging it.

This code works as expected:

View

 <div id="<%= dom_id(comment) %>_count">
   <%= Like.where("comment_id = ?", comment.id).count %>
 </div>

.js.erb response

 $("#<%= dom_id(@comment) %>_count").html("<%= Like.where('comment_id = ?', @comment.id).count %>");

However, if I add in a link_to, the response stops working. Any help on what might be going on would be greatly appreciated.

View

 <div id="<%= dom_id(comment) %>_count">
   <%= link_to Like.where("comment_id = ?", comment.id).count, "#" %>
 </div>

.js.erb response

 $("#<%= dom_id(@comment) %>_count").html("<%= link_to Like.where('comment_id = ?', @comment.id).count, "#" %>");
4

1 に答える 1

0

Your Like.where(...).count call will return an integer from the .count method, which will give you the HTML:

<a href="/">1</a>

Which is equivalent to http://yoursite.com/ with the visual label 1. This link will point to your app's root path.

Is that what you intend?

于 2012-09-07T15:59:36.030 に答える