Forum: Ruby on Rails Inline list editing with RJS: best practices

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Zack C. (Guest)
on 2006-02-14 19:59
(Received via mailing list)
I wanted to get the community opinion on the best way to use partials
inline list (<li>) editing.
I have a very common scenario where a list is rendered:

--- index.rhtml ---
  <%= render :partial => 'item', @collection => @items %>

--- _item.rhtml (simplified) ---
<li id="item_<%= %>">
  <div id="show_item_<%= %>">
    <%= h %>
    <%= link_to 'edit', . %>
  <div id="edit_item_<%= %>" style="display: none"></div>

I am using RJS templates to populate the 'edit_item' div on an ajax call
from the 'edit' link.  All very straightforward stuff.  The problem is
update in my RJS template I want to render the partial again to update
list item like this:

--- update.rjs ---
page.replace_html "item_" +, :partial => 'item'

The problem of course is that then you have nested <li> elements as the
inner text is replaced, not the entire tag.  Has anyone else encountered
this and come up with an elegant solution.  I suppose I could strip the
outer <li> elements from the partial only in the RJS call like this:

page.replace_html "item_" +,
my_method_that_strips_the_outer_li( render :partial => 'item')

But I have a feeling that there is a much more elegant way to do this.

Cody F. (Guest)
on 2006-02-14 21:16
(Received via mailing list)

Support was just added for 'replace'.  Take a look at
and, which give more detail.
I haven't actually tried it yet, but it may solve your problem. Don't
forget to do rake update_javascripts.

On 2/14/06, Zack C. <removed_email_address@domain.invalid> wrote:
> <li id="item_<%= %>">
> list item like this:
> my_method_that_strips_the_outer_li( render :partial => 'item')
> Rails mailing list
> removed_email_address@domain.invalid

Cody F.
Zack C. (Guest)
on 2006-02-14 21:46
(Received via mailing list)
Thanks Cody!
That looks like just what I was looking for!

This topic is locked and can not be replied to.