user749798
user749798

Reputation: 5370

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.

Upvotes: 3

Views: 2332

Answers (1)

jvnill
jvnill

Reputation: 29599

use escape_javascript so quotes are escaped.

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

Upvotes: 4

Related Questions