Hello, everybody A simple question... I want to add a child to an HTML element. In this case, the element is "tbody" and the HTML is a row. The insert_html method requires me to specify :after, :before, etc, which in this case is not appropriate. The insert method in the new version of prototype (1.6) allows you to specify just 2 parameters: the id of the element and the content to add to it as a child. Optionally, one can specify the position. The Insert.After, Insert.Before, etc., are now deprecated (and this is what Rails is using internally). What I ended up doing was something like: page.call("myAppendChild", id, html_content), which is calling my own js function and passing it a template rendered into a string -- not very clean I think. Is there a way to append a child to an element from within Rails without resorting to my js functions? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Aug-24 20:50 UTC
Re: Rails and prototype: adding a child to an element
On 24 Aug 2008, at 21:14, surge <gerases-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, everybody > > A simple question... > > I want to add a child to an HTML element. In this case, the element is > "tbody" and the HTML is a row. >replace or replace_html maps to Element.update which sounds like what you want. Fred> The insert_html method requires me to specify :after, :before, etc, > which in this case is not appropriate. The insert method in the new > version of prototype (1.6) allows you to specify just 2 parameters: > the id of the element and the content to add to it as a child. > Optionally, one can specify the position. The Insert.After, > Insert.Before, etc., are now deprecated (and this is what Rails is > using internally). > > What I ended up doing was something like: > > page.call("myAppendChild", id, html_content), which is calling my own > js function and passing it a template rendered into a string -- not > very clean I think. > > Is there a way to append a child to an element from within Rails > without resorting to my js functions? > > Thanks! > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Fred, thanks for the reply. See in my case, Element.update will not work because if I do a replace_html on the tbody, all the other rows will disappear and only the new one will remain. I need to add one row in addition to all other rows, whose parent is a tbody. Does it make sense?> replace or replace_html maps to Element.update which sounds like what > you want.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Aug-25 08:55 UTC
Re: Rails and prototype: adding a child to an element
On Aug 25, 1:18 am, surge <gera...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Fred, thanks for the reply. See in my case, Element.update will not > work because if I do a replace_html on the tbody, all the other rows > will disappear and only the new one will remain. I need to add one row > in addition to all other rows, whose parent is a tbody. Does it make > sense? >then surely insert_html :bottom is what you want ? Rails has/will be updated on edge to use the new Element.insert($(''foo), {bottom: stuff}) rather than Insertion.xxx Fred> > replace or replace_html maps to Element.update which sounds like what > > you want.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fred, thanks a bunch. I don''t know how I missed this in the description of the four positions. Bottom is exactly what I want. Thanks a lot! On Aug 25, 4:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Aug 25, 1:18 am, surge <gera...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Fred, thanks for the reply. See in my case,Element.update will not > > work because if I do a replace_html on the tbody, all the other rows > > will disappear and only the new one will remain. I need toaddone row > > in addition to all other rows, whose parent is a tbody. Does it make > > sense? > > then surely insert_html :bottom is what you want ? Rails has/will be > updated on edge to use the newElement.insert($(''foo), {bottom: > stuff}) rather than Insertion.xxx > > Fred > > > > replace or replace_html maps toElement.update which sounds like what > > > you want.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---