2009-12-02 66 views
1

我最近使用jRails切换到jQuery的应用程序。我以前的RJS中99%似乎完美工作,唯一的例外是使用remote_form_tag时的loading =>回调。jrails loading remote_form_tag rails

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

我有使用所提供的原型佣工

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

但使用新jRails替代之前的工作完美隐藏DIV #load_currency,这个功能似乎并没有工作?

我尝试使用RJS和jQuery直接:

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

其产品这在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;"> 

我也试过回调:前和:不是后:加载和也得到了没什么...有什么想法?或者这个功能是否不适用于jRails?

谢谢

回答

1

我觉得它更干净,以避免内联JavaScript和写入普通的旧jQuery。你可以尝试这样的事情:

# 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'); 
    }); 
});