开发者

Rails 3 Select_tag in javascript give missing ; error

开发者 https://www.devze.com 2023-04-10 17:20 出处:网络
When I write var x = \"<%= select_tag(:a开发者_如何学运维ctivity_group, options_for_select(activity_grp),{:include_blank => \'Create New Group\', :style => \'width: 100px\'}) %>\";

When I write

var x = "<%= select_tag(:a开发者_如何学运维ctivity_group, options_for_select(activity_grp),{:include_blank => 'Create New Group', :style => 'width: 100px'}) %>";

and

<% activity_grp = @activity_group.map { |ag| [ag.name, ag.id] } %>

However, I get error (missing ; before statement) in Firebug because

var x = "<select id="activity_group" name="activity_group" style="width: 100px"><option value="">Create New Group</option><option value="1">Movie</option>

 <option value="2">Report</option>";

the code generated takes more than one line. I tried html_safe as well it does not works

Can anyone guide me who came across this error before?


What do you do with x? Can this be moved into a partial? In any case, you're not trying to HTML-safe it, you're trying to JavaScript-safe it.


As per Dave answer, I solved it by JavaScript-safe

<% @x = select_tag(:activity_group, options_for_select(activity_grp),{:include_blank => 'Create New Group', :style => 'width: 100px'}) %>

and then in my JS area i wrote

var abc = "<%= escape_javascript(@x)%>";

it work fine. Hope this help

0

精彩评论

暂无评论...
验证码 换一张
取 消