1

最近、アプリに jRails を使用して jQuery に切り替えました。以前のすべての RJS の 99% は完全に機能しているようですが、唯一の例外は、remote_form_tag を使用する場合の :loading => コー​​ルバックです。

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

提供されたプロトタイプ ヘルパーを使用する前に完璧に機能する非表示の DIV #load_currency があります。

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

しかし、新しい jRails の代替手段を使用すると、この機能が機能しないように見えますか?

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;">

:loading の代わりにコールバック :before と :after も試しましたが、何も得られませんでした...何かアイデアはありますか? それとも、この機能は jRails では動作しないのでしょうか?

ありがとう

4

1 に答える 1

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');
    });
});
于 2009-12-04T10:28:37.130 に答える