Check out update_element_function: http://api.rubyonrails.com/classes/ActionView/Helpers/ JavaScriptHelper.html#M000399 This allows you to update more than one part of the page with just one ajax call, and no javascript. Thomas Am 19.07.2005 um 16:24 schrieb Matthew Margolis:> I posted a question about this a few days ago and have not gotten > any responses. I apologize for asking again but I really need to > know how to do this. > > I have a form in my application''s view that looks like > > <%= form_remote_tag :url=> > {:controller=>"note",:action=>"create_with_ajax"}, > :update=>"notes#{idea.id}", :position=> "bottom" > %> The Contents Of The Form > <%= end_form_tag %> > > When this form is submitted it currently makes one nice and working > AJAX call to (:controller => note, :action => "create_with_ajax"). > In addition to this functionality I am looking for the best way to > make it also call (:controller => note, :action > =>"update_text_listing") which updates another part of the page. > How can I achieve this functionality? If possible I would like to > minimize javascript done by hand. > > > Thank you, > Matthew Margolis > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I posted a question about this a few days ago and have not gotten any responses. I apologize for asking again but I really need to know how to do this. I have a form in my application''s view that looks like <%= form_remote_tag :url=>{:controller=>"note",:action=>"create_with_ajax"}, :update=>"notes#{idea.id}", :position=> "bottom" %> The Contents Of The Form <%= end_form_tag %> When this form is submitted it currently makes one nice and working AJAX call to (:controller => note, :action => "create_with_ajax"). In addition to this functionality I am looking for the best way to make it also call (:controller => note, :action =>"update_text_listing") which updates another part of the page. How can I achieve this functionality? If possible I would like to minimize javascript done by hand. Thank you, Matthew Margolis
Rendering a "standard" template, will include layouts which will mess with evaluate_remote response. The recommended way is to use partials, so render :partial => ... should work. Or, you can add :layout => false to rendering a normal template. Thomas Am 19.07.2005 um 17:14 schrieb Matthew Margolis:> The new note is getting saved but the visual update is not > happening. This leads me to believe that the > evaluate_remote_response in the original view or the > update_element_function in my rendered view is not setup right. >
Thomas Fuchs wrote:> Check out update_element_function: > http://api.rubyonrails.com/classes/ActionView/Helpers/ > JavaScriptHelper.html#M000399 > > This allows you to update more than one part of the page with just > one ajax call, and no javascript. > > Thomas > > Am 19.07.2005 um 16:24 schrieb Matthew Margolis: > >This is a very nice approach but I can''t quite seem to get it to work. Perhaps someone can see something I am missing. My view without the actual form fields is ----------- <div id="newnote<%=servicerequest.id%>" style="margin-left: 20px;"> <%= form_remote_tag :url=>{:controller=>"note",:action=>"create_with_ajax"}, :complete => evaluate_remote_response %> Form Contents <%= end_form_tag %> </div> ----------- My controller is ------------ def create_with_ajax @note = Note.new(@params[''notes'']) @note.written_on = Time.now @note.user_id = @session["user_id"] if @note.save render ''shared/render_note'' else render_text '''' end end ------------ My rendered view(shared/render_note) is ----------- <% update_element_function("notes#{idea.id}", :action => :update, :position => :bottom) do %> <div id="newnote" > <%= @note.written_on.to_formatted_s[0..15]%> by <%= @note.user.firstname%><br /> <%= @note.text%> </div > <br /> <br /> <%end%> -------------- The new note is getting saved but the visual update is not happening. This leads me to believe that the evaluate_remote_response in the original view or the update_element_function in my rendered view is not setup right. Thank you,, Matthew Margolis
Thomas Fuchs wrote:> Rendering a "standard" template, will include layouts which will mess > with evaluate_remote response. > > The recommended way is to use partials, so render :partial => ... > should work. Or, you can add :layout => false to rendering a normal > template. > > Thomas > > > Am 19.07.2005 um 17:14 schrieb Matthew Margolis: > > >> The new note is getting saved but the visual update is not >> happening. This leads me to believe that the >> evaluate_remote_response in the original view or the >> update_element_function in my rendered view is not setup right. >> > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsI am no longer getting errors in my logs but I am still not getting any visual changes until I refresh the page. The call is supposed to be updating the div with id= "notes#{servicerequest.id}". The note is being saved with the right id, is is possible that the wrong id is being sent to the partial? controller --------------- def create_with_ajax @note = Note.new(@params[''notes'']) @note.written_on = Time.now @note.user_id = @session["user_id"] if @note.save render :partial=> ''shared/render_note'', :locals => { :servicerequest => Servicerequest.find(@note.servicerequest_id) } else render_text '''' end end partial ------------- <% update_element_function("notes#{servicerequest.id}", :action => :update, :position => :bottom) do %> <div id="newnote" > <%= @note.written_on.to_formatted_s[0..15]%> by <%= @note.user.firstname%><br /> <%= @note.text%> </div > <br /> <br /> <%end%> view ----------- <div id="newnote<%=servicerequest.id%>" style="margin-left: 20px;"> <%= form_remote_tag :url=>{:controller=>"note",:action=>"create_with_ajax"}, :complete => evaluate_remote_response %> Note : <textarea rows="2" cols="20" name="notes[text]"></textarea> <input type="hidden" name="notes[site_id]" value="<%=servicerequest.site.id%>"> <input type="hidden" name="notes[servicerequest_id]" value="<%=servicerequest.id%>"> <input type="submit" name="submit" id="form-submit-button<%=servicerequest.id%>" value="Add note" class="button" /> <%= end_form_tag %> </div> Thank you, Matthew Margolis