Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 条件远程:根据验证为true_Javascript_Ruby On Rails_Ajax - Fatal编程技术网

Javascript 条件远程:根据验证为true

Javascript 条件远程:根据验证为true,javascript,ruby-on-rails,ajax,Javascript,Ruby On Rails,Ajax,我有一个部分\u form.html.haml中的表单,它被呈现为模态。我正在努力做到以下几点: 如果记录可以保存,请重定向到其他页面 否则,使用验证错误消息呈现模式 除了记录无效时,重定向到其他页面不起作用之外,其他一切都正常 我在\u form.html.haml中有以下内容,它被呈现为模态 = bootstrap4_form_for([:admin, donation], remote: true, html: { multipart: true, id: 'manual_donation

我有一个部分
\u form.html.haml
中的表单,它被呈现为模态。我正在努力做到以下几点:

  • 如果记录可以保存,请重定向到其他页面
  • 否则,使用验证错误消息呈现模式
  • 除了记录无效时,重定向到其他页面不起作用之外,其他一切都正常

    我在
    \u form.html.haml
    中有以下内容,它被呈现为模态

    = bootstrap4_form_for([:admin, donation], remote: true, html: { multipart: true, id: 'manual_donations', autocomplete: 'nope'}) do |f|
     # form with submit_button which calls `create` action of `donations_controller.rb`
    
    这是我的
    new.js.erb
    ,它呈现了上述模式:

    $('#newDonation').modal('hide');
    $('#newDonation, .modal-backdrop').remove();
    $('body').append("<%= j render partial: 'donation_modal' %>");
    $('#newDonation').modal('show')
    
    当我单击带有有效记录的模式的submit按钮时,页面不会重定向,我在控制台上收到以下消息:

    Processing by Admin::DonationsController#index as JS
    -----------
    No template found for Admin::DonationsController#index, rendering head :no_content
    

    我有
    app/views/admin/investments/
    下的视图
    index.html.haml
    。当我从
    \u form.html.haml
    中删除
    remote:true
    时,重定向工作正常。但是,在这种情况下,使用验证错误消息呈现
    new.js.erb
    将不起作用。我真的不知道如何处理这种情况。

    这个
    index.html.haml
    在哪里?它必须在app/views/admin/investments/下。它在app/views/admin/investments/下。当我从表单中删除
    remote:true
    时,重定向工作
    Processing by Admin::DonationsController#index as JS
    -----------
    No template found for Admin::DonationsController#index, rendering head :no_content