# Inline editing with rjs - problem

**URL:** <https://www.ruby-forum.com/t/inline-editing-with-rjs-problem/125256>\
**Category:** Rails\
**Created:** [January 7, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/inline-editing-with-rjs-problem/125256 "2008-01-07T15:44:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![n1c](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ec8ea/32.png) [@n1c](https://www.ruby-forum.com/u/n1c)\
**Post date:** [January 7, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/inline-editing-with-rjs-problem/125256/1 "2008-01-07T15:44:44Z")

</div>

I have a page with two fields that are inline-editable. Although both  
fields are saved after submitting changes, I can’t get the first field  
to display the new value - it always spits our raw js. The 2nd field  
works no problem.

I have this in my view:

\<%=h @photo.caption || 'None yet' %\>

 \<%= javascript\_tag "$('caption').addClassName('rollover')"%\> \<%= javascript\_tag "$('caption').onclick=function(){ $('caption').toggle(); $('rename\_caption').toggle(); }" %\> \<% remote\_form\_for ([@event, @photo]), :url =\> event\_photo\_url(@event, @photo), :html =\> {:method =\> :put}, :update =\> 'caption', :before =\> "$('caption').update('Saving...'); $('caption').toggle(); $('rename\_caption').toggle();" do |f| %\> \<%= f.text\_area :caption, :cols =\> 40, :rows =\> 3 %\>\<%= submit\_tag 'Update' %\> \<%= link\_to\_function "Cancel" do |page| page.toggle :caption, :rename\_caption end %\> \<% end %\>

\<%= show\_tag\_list %\>

 \<%= javascript\_tag "$('tags').addClassName('rollover')"%\> \<%= javascript\_tag "$('tags').onclick=function(){ $('tags').toggle(); $('rename\_tags').toggle(); }" %\> \<% remote\_form\_for ([@event, @photo]), :url =\> event\_photo\_url(@event, @photo), :html =\> {:method =\> :put}, :update =\> 'tag\_list', :before =\> "$('tags').update('Saving...'); $('tags').toggle(); $('rename\_tags').toggle();" do |f| %\> \<%= f.text\_field :tag\_list %\>\<%= submit\_tag 'Update' %\> \<%= link\_to\_function "Cancel" do |page| page.toggle :tags, :rename\_tags end %\> \<% end %\>

And the following in my controller:

def update  
@photo = @event.photos.find(params[:id])

```
respond_to do |format|
  if @photo.update_attributes(params[:photo])
    flash[:notice] = 'Photo was successfully updated.'
    format.html { redirect_to(event_photos_url(@event)) }
    format.xml { head :ok }
    format.js { render :update do |page|
                  page[:caption].replace_html :partial => 'caption'
                  page[:tags].replace_html :partial => 'tag_list'
                end }
  else
    format.html { render :action => "edit" }
    format.xml { render :xml => @photo.errors, :status =>

```

:unprocessable\_entity }  
end  
end  
end

I’m completely stumped as to why it refreshes the values when updating  
the 2nd field (the tags), but not when I update the caption.

This is the js it puts instead of the new caption:

try { $(“caption”).update(“this is a dog of course\n”);  
$(“tags”).update(“dog, food, cat, fish”); } catch (e) { alert(‘RJS  
error:\n\n’ + e.toString()); alert(’$(“caption”).update(“this is a  
dog of course\n”);\n$(“tags”).update(“dog, food, cat, fish”);’);  
throw e }

Any ideas?

Thx  
Nick

---

<div class="post-metadata">

**Author:** ![n1c](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ec8ea/32.png) [@n1c](https://www.ruby-forum.com/u/n1c)\
**Post date:** [January 7, 2008, 3:49pm UTC](https://www.ruby-forum.com/t/inline-editing-with-rjs-problem/125256/2 "2008-01-07T15:49:25Z")

</div>

Nick C. wrote:

> I have a page with two fields that are inline-editable. Although both  
> fields are saved after submitting changes, I can’t get the first field  
> to display the new value - it always spits our raw js. The 2nd field  
> works no problem.

[http://dev.rubyonrails.org/ticket/10055](http://dev.rubyonrails.org/ticket/10055)

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![n1c](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ec8ea/32.png) [@n1c](https://www.ruby-forum.com/u/n1c)\
**Post date:** [January 7, 2008, 8:14pm UTC](https://www.ruby-forum.com/t/inline-editing-with-rjs-problem/125256/3 "2008-01-07T20:14:15Z")

</div>

Mark Reginald J. wrote:

> [http://dev.rubyonrails.org/ticket/10055](http://dev.rubyonrails.org/ticket/10055)

Call me stupid, but where exactly would I edit to apply that patch?

Thx  
Nick
