Hello everybody, In a controller I try to render a javascript google ad to print it into some HTML using JSONP, like this <script type="text/javascript"><!-- google_ad_client = "pub-23222424"; google_alternate_color = "FFFFFF"; google_ad_width = 468; google_ad_height = 60; //--></script> <script type="text/javascript" src="http://pagead2.google.com/pgad/show_ads.js"> </script> So I do: render :text "var s_response = { content: ''<script type=\"text/ javascript\"><!--\\ngoogle_ad_client = \"pub-23222424\";\ \ngoogle_alternate_color = \"FFFFFF\";\\ngoogle_ad_width = 468;\ \ngoogle_ad_height = 60;\\n//--><\\/script>\\n<script type=\"text/ javascript\"\\n src=\"http://pagead2.google.com/pgad/show_ads.js\">\ \n<\\/script>'', id: ''2''};"> But i get this error: unterminated string literal [Break on this error] var response = { content: ''<script type="text/ javascript"><!-- => That seems like it is a multilines problem right ? But I don''t know how to resolve it. Thanks, Lucas -- 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.
Marnen Laibow-Koser
2010-Aug-03 18:00 UTC
Re: rendering multiline Javascript by using JSONP in rails
Lucas wrote:> Hello everybody, > > In a controller I try to render a javascript google ad to print it > into some HTML using JSONP, like this > > <script type="text/javascript"><!-- > google_ad_client = "pub-23222424"; > google_alternate_color = "FFFFFF"; > google_ad_width = 468; > google_ad_height = 60; > //--></script> > <script type="text/javascript" > src="http://pagead2.google.com/pgad/show_ads.js"> > </script> > > So I do: > > render :text "var s_response = { content: ''<script type=\"text/ > javascript\"><!--\\ngoogle_ad_client = \"pub-23222424\";\ > \ngoogle_alternate_color = \"FFFFFF\";\\ngoogle_ad_width = 468;\ > \ngoogle_ad_height = 60;\\n//--><\\/script>\\n<script type=\"text/ > javascript\"\\n src=\"http://pagead2.google.com/pgad/show_ads.js\">\ > \n<\\/script>'', id: ''2''};"> > > But i get this error: > > unterminated string literal > > [Break on this error] var response = { content: ''<script type="text/ > javascript"><!-- > > => That seems like it is a multilines problem right ?No. The problem is that your double-quoted string contains double quotes!> But I don''t know > how to resolve it.There are quoting constructs that would do the trick. But you have a bigger problem: you really shouldn''t be doing this in the controller. Rendered JS, like rendered HTML, belongs in the view.> > Thanks, > > LucasBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.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.
> No. The problem is that your double-quoted string contains double > quotes!It contains double-quotes but they are escaped aren''t they ?> There are quoting constructs that would do the trick. But you have a > bigger problem: you really shouldn''t be doing this in the controller. > Rendered JS, like rendered HTML, belongs in the view.In fact this code isn''t print in my HTML but in the HTML of another website, thiat is why it is in a controller and not a view Thanks, Lucas -- 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.
Marnen Laibow-Koser
2010-Aug-03 19:29 UTC
Re: rendering multiline Javascript by using JSONP in rails
Lucas wrote:>> No. �The problem is that your double-quoted string contains double >> quotes! > > It contains double-quotes but they are escaped aren''t they ?Whoops! You''re right. I somehow overlooked the backslashes.> >> There are quoting constructs that would do the trick. �But you have a >> bigger problem: you really shouldn''t be doing this in the controller. >> Rendered JS, like rendered HTML, belongs in the view. > > In fact this code isn''t print in my HTML but in the HTML of another > website, thiat is why it is in a controller and not a viewDoesn''t matter. If it goes to the user''s browser, it should generally be in a view.> > Thanks, > > LucasBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.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.