SyntaxError:rails app中未终止的字符串文字

时间:2015-11-24 13:33:19

标签: jquery ruby-on-rails ruby-on-rails-4

我在这里得到了上述错误。我的代码是

 $("#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

2 个答案:

答案 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 %>")