Hi everybody, I would like to add javascript tags dynamically to my view. So I used the following code : @events.each do |e| %(javascript_tag ''new Popup(''event_popup_#{e.id}'',''event_link_#{e.id}'')'') end However it seems the code is not being added to my DOM. How can I correctly code this ? Thanks in advance. Joel --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What''s wrong with doing this: <script> new Popup(''event_popup_#{e.id}'',''event_link_#{e.id}'') </script> ? On Fri, Mar 28, 2008 at 11:00 PM, joel <joel.sooriah-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi everybody, > > I would like to add javascript tags dynamically to my view. So I used > the following code : > > @events.each do |e| > > %(javascript_tag ''new > Popup(''event_popup_#{e.id}'',''event_link_#{e.id}'')'') > > end > > However it seems the code is not being added to my DOM. > > How can I correctly code this ? > > Thanks in advance. > > Joel > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes of course ;-) ! Thank you very much... Joel --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
joel wrote:> Hi everybody, > > I would like to add javascript tags dynamically to my view. So I used > the following code : > > @events.each do |e| > > %(javascript_tag ''new > Popup(''event_popup_#{e.id}'',''event_link_#{e.id}'')'') > > end%() declares a string literal, so nothing happens to your javascript_tag. And .each won''t return your string - even the correct one. Try this eRB: <% @events.map do |e| javascript_tag "new Popup(''event_popup_#{e.id}'',''event_link_#{e.id}'');" end %> That still has its own style issues, including it will push several <script> tags in, not just one efficient one. You could also try this: <%= javascript_tag @events.map{|e| "new Popup(''event_popup_#{e.id}'',''event_link_#{e.id}'');" }.join %> So that puts the <script> tag on the outside, and the "unrolled loop" on the inside. -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---