# Inline list editing with RJS: best practices

**URL:** <https://www.ruby-forum.com/t/inline-list-editing-with-rjs-best-practices/53805>\
**Category:** Rails\
**Created:** [February 14, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/inline-list-editing-with-rjs-best-practices/53805 "2006-02-14T18:59:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [February 14, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/inline-list-editing-with-rjs-best-practices/53805/1 "2006-02-14T18:59:59Z")

</div>

I wanted to get the community opinion on the best way to use partials  
and  
inline list (

- ) editing.  
I have a very common scenario where a list is rendered:

— index.rhtml —

 \<%= render :partial =\> 'item', @collection =\> @items %\>

— \_item.rhtml (simplified) —

- 
 \<%= h item.name %\> \<%= link\_to 'edit', . %\> 

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  
on  
update in my RJS template I want to render the partial again to update  
the  
list item like this:

— update.rjs —  
page.replace\_html “item\_” + item.id.to\_s, :partial =\> ‘item’

The problem of course is that then you have nested

- 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 
- page.replace\_html “item\_” + item.id.to\_s,  
my\_method\_that\_strips\_the\_outer\_li( render :partial =\> ‘item’)

---

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [February 14, 2006, 8:16pm UTC](https://www.ruby-forum.com/t/inline-list-editing-with-rjs-best-practices/53805/2 "2006-02-14T20:16:03Z")

</div>

Zack,

Support was just added for ‘replace’. Take a look at  
[http://dev.rubyonrails.org/changeset/3590](http://dev.rubyonrails.org/changeset/3590)  
and [http://dev.rubyonrails.org/changeset/3579](http://dev.rubyonrails.org/changeset/3579), 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](mailto:removed_email_address@domain.invalid) wrote:

> - list item like this: my\_method\_that\_strips\_the\_outer\_li( render :partial =\> 'item') Rails mailing list removed\_email\_address@domain.invalid http://lists.rubyonrails.org/mailman/listinfo/rails

–  
Cody F.  
[http://www.codyfauser.com](http://www.codyfauser.com)

---

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [February 14, 2006, 8:46pm UTC](https://www.ruby-forum.com/t/inline-list-editing-with-rjs-best-practices/53805/3 "2006-02-14T20:46:33Z")

</div>

Thanks Cody!  
That looks like just what I was looking for!

Zack
