Inline editing with rjs - problem

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

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


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

Mark Reginald J. wrote:

http://dev.rubyonrails.org/ticket/10055

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

Thx
Nick

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs