我在这里得到了上述错误。我的代码是
$("#customers").append(
'<%= select_tag "customer_id", options_from_collection_for_select(@customers, "id", "name"), include_blank: true %>'
);
在控制台中,它指向此行的错误
'<select id="customer_id" name="customer_id"><option v
答案 0 :(得分:2)
尝试添加escape_javascript,如下所示,这将解决您的问题。
$("#customers").append("<%= escape_javascript(select_tag('customer_id', options_from_collection_for_select(@customers, :id, :name), include_blank: true)) %>")
答案 1 :(得分:-1)
使用双引号(&#34;&#34;)而不是单引号(&#39;&#39;): -
$("#customers").append("<%= select_tag 'customer_id', options_from_collection_for_select(@customers, :id, :name), include_blank: true %>")