jrails加载remote_form_tagrails

发布于 2024-08-13 14:46:54 字数 1239 浏览 3 评论 0原文

我最近在一个应用程序中使用 jRails 切换到 jQuery。我之前的 RJS 99% 似乎都能完美运行,唯一的例外是 :loading =>;使用remote_form_tag时的回调。

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

我还尝试了回调 :before 和 :after 而不是 :loading 并且什么也没有...有什么想法吗?或者这个功能不适用于 jRails?

谢谢

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("#load_currency").fadeIn();}, data:jQuery.param(jQuery(this).serializeArray()) + '&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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你再特殊 2024-08-20 14:46:54

我发现避免内联 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');
    });
});

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');
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文