I generated a Patch for Rails to add the ability to do what you want, as I
had the same issue - http://dev.rubyonrails.org/ticket/3246
To work around this with the existing code, and without applying the patch,
you can change your edit.rjs to this (copied from the patch code, written in
email, so may need a little work):
partial = render :partial => ''item''
page << "var html = ''#{partial}'';"
page << "element = $(#{item.id});"
page << "if (element.outerHTML) {"
page << " element.outerHTML = html.stripScripts();"
page << "} else {"
page << " var range = element.ownerDocument.createRange();"
page << " range.selectNodeContents(element);"
page << " element.parentNode.replaceChild("
page << " range.createContextualFragment(html.stripScripts()),
element);"
page << "}"
-----Original Message-----
From: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Roman Ilin
Sent: Friday, January 20, 2006 8:27 AM
To: rails@lists.rubyonrails.org
Subject: [Rails] Update HTML Element with Ajax
I have following files.
list.rhtml
-----------------------
<ul id="items">
<%= render(:partial => ''item'', :collection =>
@items) %>
</ul>
_item.rhtml
------------------------
<li id="<%= item.id %>" >
<%= item.name %>
<%= item.body %>
</li>
edit.rjs
------------------------
page.replace_html @item.id, :partial=>''item''
if I call /items/list I will get
<ul id="items">
<li id="item_1">...</li>
<li id="item_2">...</li>
...
</ul>
And wenn I edit first item I will get
<ul id="items">
<li id="item_1"><li
id="item_1">...</li></li>
<li id="item_2">...</li>
...
</ul>
Sure I can controll it in _item.rhtml partial like this
_item.rhtml
------------------------
<% if some_merker %>
<li id="<%= item.id %>" >
<% end %>
<%= item.name %>
<%= item.body %>
<% if some_merker %>
</li>
<% end %>
and then set this merker=true for list-action and false for others, but
it''s unelegant.
Some Ideas?
Sorry for my english.
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails