Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 942
user749798 Avatar asked Feb 01 '26 05:02

user749798


1 Answers

use escape_javascript so quotes are escaped.

$(".commentvotecount<%= params[:commentid]%>").html("<%= escape_javascript link_to('About', '/about') %>");
like image 112
jvnill Avatar answered Feb 03 '26 19:02

jvnill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!