<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Paul On Rails: Tag Ajax</title>
    <link>http://paulonrails.com/articles/tag/ajax</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Paul's thoughts on Rails</description>
    <item>
      <title>in_place_editor_field and multiple element updates</title>
      <description>This one took me a while to figure out so hopefully it'll be useful for someone out there.  I had a fairly simple need, an in_place_editor_field that updates multiple elements.  The main trick here is to make sure the &lt;b&gt;:script =&gt; true&lt;/b&gt; option gets passed in.&lt;br /&gt;
&lt;br /&gt;
In the View do the following
&lt;pre&gt;&amp;lt;%= in_place_editor_field :asset, :name,
 { :id =&amp;gt; &amp;quot;in_place_editor_#{@asset.dom_id}&amp;quot; }, 
:script =&amp;gt; true %&amp;gt;&lt;/pre&gt;

And in the Controller
&lt;pre&gt;
  def set_asset_name
    asset  = Asset.find_by_id(params[:id])
    old_value = asset.name
    asset.name = params[:value]
    asset.name = old_value unless asset.save

    render :update do | page |
      page.replace_html "edit_#{asset.dom_id}", asset.name  
      page.replace_html "in_place_editor_#{asset.dom_id}", asset.name  
    end
  end
&lt;/pre&gt;

Again the key is to make sure the &lt;b&gt;:script =&gt; true&lt;/b&gt; option is set, otherwise you'll get the JS code generated by the render :update instead of the new value.

</description>
      <pubDate>Thu, 29 Nov 2007 17:50:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:b51e3e42-3d27-4c03-af95-d7670568014e</guid>
      <author>Paul Haddad</author>
      <link>http://paulonrails.com/articles/2007/11/29/in_place_editor_field-and-multiple-element-updates</link>
      <category>Code</category>
      <category>Ajax</category>
      <category>in_place_editor_field</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
