On 05 Sep 2009, at 10:28, Heinz Strunk wrote:

>>> A much better solution than patching the rails helpers would be to  
>>> add
>>> the following to public/javascripts/application.js (it adds a nice
>>> little fade in and fade out too):
>>>
>>> Ajax.Responders.register({
>>>    onCreate: function() {
>>>      new Effect.Appear('loading', { duration: 0.3 });
>>>      },
>>>    onComplete: function(request, transport, json) {
>>>      if (0 == Ajax.activeRequestCount) {
>>>        new Effect.Fade('loading', { duration: 0.3 });
>>>      }
>>>      if(!request.success()) {
>>>  alert('An error occurred while processing this request');
>>>      }
>>>    }
>>> });
>>>
>>>
>>
>> It does indeed look pretty cool but it only works on the first click.
>> It's not showing when I click somewhere else afterwards.

> Accidently removed the div. It's working. Thanks!


The major advantages of using this method are:
- Less code litter in views (since patching the rails helper would put  
that code on every remote link you use)
- Race conditions would make your rails helper fail:
   Example:
   • search number 1 is fired => loader shows
   • user immediately corrects and fires of a second request => loader  
keeps on showing but flashes
   • first request finished, but second one is still running => loader  
would disappear

Using the global Ajax.Responders checks if every request is finished  
before hiding the loader.



Best regards

Peter De Berdt


--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to