Ruby on Rails - problems with the Ajax response

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, "#" %>");

Answers


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?


Need Your Help

How to host a wordpress blog from a domain pointed to an app hosted with google app engine?

wordpress google-app-engine dns a-records

I have a Python web app hosted with Google App Engine with a .com pointed towards the App Engine app. I would like to start a Wordpress blog at mydomain.com/blog.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.