When I write var x = "<%= select_tag(:activity_group, options_for_select(activity_grp),{:include_blank => ''Create New Group'', :style => ''width: 100px''}) %>"; where <% 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 without concat the entire output. I tried html_safe as well it does not works Can anyone guide me who came across this error before? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Dave Aronson
2011-Oct-06 13:26 UTC
Re: Rails 3 Select_tag in javascript give missing ; error
On Tue, Oct 4, 2011 at 21:07, Viral <p.viral.p-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> var x = "<select id="activity_group" name="activity_group"The problem is probably that you''re using double-quotes inside a double-quoted string. Not sure if the ERB processing will process this if you enclose the whole thing in single quotes, which would be the easiest fix. If that doesn''t work (in many contexts, single quotes are taken as "leave this stuff alone, don''t process it in any way"), try escaping the interior double quotes before actually using the var''s value. (Don''t just replace them with single quotes, since many browsers don''t recognize those for attributes.) -Dave -- LOOKING FOR WORK, preferably Ruby on Rails, in NoVa/DC; see main web site. Main Web Site: davearonson.com Programming Blog: codosaur.us Excellence Blog: dare2xl.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Oct-06 14:23 UTC
Re: Rails 3 Select_tag in javascript give missing ; error
On Oct 6, 2:26 pm, Dave Aronson <googlegroups2d...-BRiZGj7G2yRXqviUI+FSNg@public.gmane.org> wrote:> On Tue, Oct 4, 2011 at 21:07, Viral <p.vira...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > var x = "<select id="activity_group" name="activity_group" > > The problem is probably that you''re using double-quotes inside a > double-quoted string. Not sure if the ERB processing will process > this if you enclose the whole thing in single quotes, which would be > the easiest fix. If that doesn''t work (in many contexts, single > quotes are taken as "leave this stuff alone, don''t process it in any > way"), try escaping the interior double quotes before actually using > the var''s value. (Don''t just replace them with single quotes, since > many browsers don''t recognize those for attributes.) >An easy way of doing this is to use to_json, i.e. var x = <%= select_tag(...).to_json %> since this turns what it is called on into a json object, which is near a dammit a valid js literal (apparently there is one of the unicode white space character which is valid in json but has to be escaped in javascript (or vice versa, I don''t quite recall), but I''ve never run into this in the wild) There''s also the escape_javascript helper Fred> -Dave > > -- > LOOKING FOR WORK, preferably Ruby on Rails, in NoVa/DC; see main web site. > Main Web Site: davearonson.com > Programming Blog: codosaur.us > Excellence Blog: dare2xl.com-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks you guys for prompt response. It was helpful. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/rdACUO59qUAJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.