Hi, I''m programming a Ruby on Rails project where I am on the edit page of /boxes/1/edit and I''m trying to make an InPlaceEditor for the color property. (E.g. red box, blue box, etc.) My problem is that after successfully saving the value in the database, the response I get from the server is javascript, and it''s being rendered in the place where the updated value is supposed to be. Here is my view: <b>Color</b><br /> <p id=''edit_field''><%= @box.color %></p> <script type="text/javascript"> new Ajax.InPlaceEditor($(''edit_field''), ''/boxes/1'', { ajaxOptions: {method: ''put''}, callback: function(form, value) { return ''authenticity_token='' + window._token + ''&box[color]='' + escape(value) } }); </script> In my controller, I didn''t do anything special except add the format.js property. def update @box = Box.find(params[:id]) respond_to do |format| if @box.update_attributes(params[:box]) format.js format.html { redirect_to(@box) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @box.errors, :status => :unprocessable_entity } end end end In my RJS file, I just try to update my box, and update the field with the new value. page << "set_box_properties(''#{@box.nom}'',''#{ @box.color}'', #{@box.x}, #{@box.y}, #{@box.width}, #{@box.height});" page[''edit_field''].value = "red" I tried setting htmlResponse: false, I think that solved the problem, but now I just see "Saving . . . . ." How do I update it with the latest value? Am I doing this right? Is there a better way to do in- place editing? I couldn''t get the plugins of the Ruby wrappers to prototype/scriptaculous to work with Rails 2.0.... with the authenticity token problem etc. Is there a "standard" fix for this? Thank you, David :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> I tried setting htmlResponse: false, I think that solved the problem, > but now I just see "Saving . . . . ." How do I update it with the > latest value?Why are you only responding to the JS content type if the save was successful. You need to handle both situations. Also, if you''re going to turn evalScripts on (htmlResponse:false) then you need to handle updating the element with some returned javascript. Something like: render :update do |page| page.replace_html ''edit_field'', ''the new value'' end Lastly, with your respond_to block, the format.html call needs to be first. You will have issues in IE if you don''t do this. Like:> respond_to do |format| > format.html { redirect_to(@box) } > format.js > format.xml { head :ok }-justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
The reason I turned off the htmlResponse was cuz the try{...} catch(e) {...} javascript was being displayed where the updated value is supposed to be. I got the "Saving . . . . ." to be updated with the box color by adding $(''edit_field'').update(''#{@box.color}''); For some reason $ (''edit_field'').value = ..... wasn''t working but .update did do the trick. So my RJS looks like: page << "set_box_properties(''#{@box.nom}'',''#{ @box.color}'', #{@box.x}, #{@box.y}, #{@box.width}, #{@box.height});$ (''edit_field'').update(''#{@box.color}'')"> render :update do |page| > page.replace_html ''edit_field'', ''the new value'' > endAhh... I think this is what I was looking for..... This goes in the RJS file right? Thanks a lot!> Lastly, with your respond_to block, the format.html call needs to be > first. You will have issues in IE if you don''t do this. Like:Thanks for that tip! David :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> Why are you only responding to the JS content type if the save was > successful. You need to handle both situations. Also, if you''re goingYeah it''s weird. When I take out htmlResponse:false from my view, and put in my RJS file: render :update do |page| page.replace_html ''edit_field'', @box.color end Then I get the javascript appearing where the box color should be. try { set_box_properties(''box_1'',''red'', 562, 220, 300, 200); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''set_box_properties(\''box_1\'',\''red\'', 562, 220, 300, 200);''); throw e } hm....> to turn evalScripts on (htmlResponse:false) then you need to handle > updating the element with some returned javascript. > > Something like: > > render :update do |page| > page.replace_html ''edit_field'', ''the new value'' > end > > Lastly, with your respond_to block, the format.html call needs to be > first. You will have issues in IE if you don''t do this. Like: > > > respond_to do |format| > > format.html { redirect_to(@box) } > > format.js > > format.xml { head :ok } > > -justin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> Why are you only responding to the JS content type if the save was > successful. You need to handle both situations. Also, if you''re goingYeah it''s weird. When I take out htmlResponse:false from my view, and put in my RJS file: render :update do |page| page.replace_html ''edit_field'', @box.color end Then I get the javascript appearing where the box color should be. try { set_box_properties(''box_1'',''red'', 562, 220, 300, 200); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''set_box_properties(\''box_1\'',\''red\'', 562, 220, 300, 200);''); throw e } hm....> to turn evalScripts on (htmlResponse:false) then you need to handle > updating the element with some returned javascript. > > Something like: > > render :update do |page| > page.replace_html ''edit_field'', ''the new value'' > end > > Lastly, with your respond_to block, the format.html call needs to be > first. You will have issues in IE if you don''t do this. Like: > > > respond_to do |format| > > format.html { redirect_to(@box) } > > format.js > > format.xml { head :ok } > > -justin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Mon, Apr 7, 2008 at 9:30 AM, David Beckwith <dbitsolutions-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> adding $(''edit_field'').update(''#{@box.color}''); For some reason $ > (''edit_field'').value = ..... wasn''t working but .update did do the > trick.That''s because the element with an ID of ''edit_field'' is your paragraph, not your input control. You cannot set a value on a paragraph element like that.> Ahh... I think this is what I was looking for..... This goes in the > RJS file right?It can, or it can just go inline in your action.... def foo respond_to do |format| format.html {} format.xml {} format.js do render :update do |page| page.replace_html ''foo'', ''bar'' end end end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- Strange behaviour with Scriptaculous v 1.7.0 beta 2
- Highlighint rjs problem on a new product
- Graceful degrading AJAX show/hide
- padawan seeks advice from jedi masters to create toggle box via ajax/rjs before slitting wrists with ruby powered light-saber.
- How to make an AJAX call to different domains in Ruby on Rails 3.0