[英]Nested quotes in link_to helper within js.erb file
I'm trying to get this to work in my votes.js.erb file I'm using for my ajax request but it's not spitting out anything. 我试图在我的ajax请求中使用的我的polls.js.erb文件中使它工作,但它不会吐出任何东西。
<% if current_user && @micropost.has_evaluation?(:votes, current_user) %>
$("#vote<%= @micropost.id %> a").html('<%= link_to "<i class='fa fa-heart fa-3x'></i>".html_safe, vote_micropost_path(@micropost, type: "down"), :method => :post, :remote => true %>')
<% else %>
$("#vote<%= @micropost.id %> a").html('<%= link_to "<i class='fa fa-heart-o fa-3x'></i>".html_safe, vote_micropost_path(@micropost, type: "up"), :method => :post, :remote => true %>')
<% end %>
It has to do with the nested quotations but I can't find the right combo. 它与嵌套报价有关,但我找不到正确的组合。 I've been trying different things like using \\ to escape the inner quotes and also "
我一直在尝试使用\\来转义内部引号和"
but this doesn't seem to work for me either with this this code 但这对这段代码似乎也不适合我
<% if current_user && @micropost.has_evaluation?(:votes, current_user) %>
$("#vote<%= @micropost.id %> a").html("<%= escape_javascript(link_to '<i class="fa fa-heart fa-3x"></i>'.html_safe, vote_micropost_path(@micropost, type: 'down'), :method => :post, :remote => true %>")
<% else %>
$("#vote<%= @micropost.id %> a").html("<%= escape_javascript(link_to '<i class="fa fa-heart-o fa-3x"></i>'.html_safe, vote_micropost_path(@micropost, type: 'up'), :method => :post, :remote => true %>")
<% end %>
Try 尝试
<% if current_user && @micropost.has_evaluation?(:votes, current_user) %>
$("#vote<%= @micropost.id %> a").html('<%= link_to "<i class=\"fa fa-heart fa-3x\"> </i>".html_safe, vote_micropost_path(@micropost, type: "down"), :method => :post, :remote => true %>')
<% else %>
$("#vote<%= @micropost.id %> a").html('<%= link_to "<i class=\"fa fa-heart-o fa-3x\"></i>".html_safe, vote_micropost_path(@micropost, type: "up"), :method => :post, :remote => true %>')
<% end %>
or use 或使用
$("#vote<%= @micropost.id %> a").html('<%= link_to content_tag('i', class: 'fa fa-heart fa-3x'), vote_micropost_path(@micropost, type: "down"), :method => :post, :remote => true %>')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.