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:
<div id="caption"><%=h @photo.caption || ''None
yet'' %></div>
<div id="rename_caption" style="display:none">
<%= 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 %>
</div>
<div id="tags"><%= show_tag_list %></div>
<div id="rename_tags" style="display:none">
<%= 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 %>
</div>
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---