views:

388

answers:

1

I recently switched to jQuery using jRails for an app. 99% of all my previous RJS seems to work perfectly, the only except is the :loading => callback when using the remote_form_tag.

<% form_remote_tag :url => '/hostels/update_currency', :loading => visual_effect(:appear, :load_currency), :html => { :id => 'currency' } do %>

I have a hidden DIV #load_currency which worked perfect before using the provided prototype helpers

http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001648

But using the new jRails alternative, this feature doesn't seem to work?

I tried using RJS and jQuery directly:

:loading => visual_effect(:appear, :load_currency)
:loading => "$('#load_currency').show();"

which product this in the html:

onsubmit="jQuery.ajax({beforeSend:function(request){jQuery(&quot;#load_currency&quot;).fadeIn();}, data:jQuery.param(jQuery(this).serializeArray()) + '&amp;authenticity_token=' + encodeURIComponent('O7Y7wzFoPPxGSTxIb2bQ3zshrUP+h1OGAUdtyzdQz0A='), dataType:'script', type:'post', url:'/hostels/update_currency'}); return false;">

I also tried the callbacks :before and :after instead of :loading and also got nothin... any ideas? Or does this feature just not work with jRails?

Thanks

+1  A: 

I find it cleaner to avoid the inline javascript and write plain old jquery. You might try something like this:

# view.html.erb
<% form_tag '/hostels/update_currency', :html => { :id => 'currency' } do %>
...


# some_included_javascript_file.js
$(function() {
    $('#currency').submit(function() {
        $('#load_currency').show(); // or do an effect
        $.post(this.action, jQuery.param(jQuery(this).serializeArray()), function() {
            $('#load_currency').hide(); // or do an effect
        }, 'script');
    });
});
Amiel Martin