Tim Case
2005-Sep-02 16:34 UTC
Agile Web Dev with Rails: The Web, V2.0 - Bug in Multiple Updates?
Hi All, Has anyone been able to the code listed under Multiple Updates to run as described? Multiple updates is updating more than one DOM element after a link_to_remote call. Muiltiple Updates is page 392 in my PDF and begins: "If you rely heavily on the server to do client-side updates, and need more flexibility than the :update => ''elementid'' construct provides, callbacks may be the answer. The trick is to have the server send JavaScript to the client as part of an AJAX response. As this JavaScript has full access to the DOM, it can update as much of the browser window as you need. To pull off this magic, use :complete => "eval(request.responseText)" instead of :update. You can generate JavaScript within your view that is then delivered to the client and executed. " I''ve tried running this code downloaded from the PragProg site and can''t reproduce the results. The other Ajax examples seem to work okay. Can anyone confirm or deny that this code works so I can try to figure out if I have some sort of environment issue? Thanks! Tim Case tcrails2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
2005-Sep-02 17:57 UTC
Re: Agile Web Dev with Rails: The Web, V2.0 - Bug in Multiple Updates?
Hi ! Tim Case said the following on 2005-09-02 12:34:> as you need. To pull off this magic, use :complete => > "eval(request.responseText)" instead of :update. You can generate > JavaScript within your view that is then delivered to the client and > executed. " > > I''ve tried running this code downloaded from the PragProg site and can''t > reproduce the results. The other Ajax examples seem to work okay. > > Can anyone confirm or deny that this code works so I can try to figure > out if I have some sort of environment issue?I can confirm that it works. In fact, this is how I do it: function acceptDrop(draggable, droppable, event) { var team = draggable.parentNode.getAttribute(''team''); if (null == team) team = ''''; var copy = false; if (event.ctrlKey) copy = true; new Ajax.Request(''<%= url_for :action => ''reschedule'' %>'', {onLoading: function(request) { Element.hide(''message-area''); new Effect.Fade(draggable);}, onComplete: function(request) { <%= evaluate_remote_response %>}, method: ''post'', parameters: ''item='' + draggable.id + ''&time_slot='' + droppable.element.id + ''&team='' + team + ''©='' + copy}); } Notice the onComplete handler in my Ajax.Request. My reschedule view looks like this: <%= update_element_function(''schedule-container'', :content => render(:partial => ''schedule'')) -%> <%= update_element_function(''message-area'', :content => %Q(<div class="message">#{flash[:notice]}</div>)) unless flash[:notice].blank? -%> <%= visual_effect(:appear, ''message-area'') unless flash[:notice].blank? -%> <%= update_element_function(''unscheduled'', :content => render(:partial => ''unscheduled'', :collection => Job.unscheduled)) -%> NOTE: onDrop() as shown above wouldn''t allow you access to the event object. You need a patched copy of the dragdrop.js library which passes the event object to the callbacks. Hope that helps ! François