Search code examples
javascriptjqueryruby-on-railsruby-on-rails-3link-to

link_to in .js.erb file


For some reason, when I use link_to in my show.js.erb file, the javascript does not work...

This works:

$(".commentvotecount<%= params[:commentid]%>").html("<%= positiveVoteCount = @comment.plusminus %>");

This doesn't:

$(".commentvotecount<%= params[:commentid]%>").html("<%= positiveVoteCount = @comment.plusminus %> <%= link_to 'About', '/about' %>");

What is going wrong?

Thank you.


Solution

  • use escape_javascript so quotes are escaped.

    $(".commentvotecount<%= params[:commentid]%>").html("<%= escape_javascript link_to('About', '/about') %>");