Rails and prototype: adding a child to an element

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!

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

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?

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

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!