Jquery Rails 3… form submits twice… deletes twice… help

前端 未结 4 863
盖世英雄少女心
盖世英雄少女心 2020-12-18 11:21

It seems like eveyone has this problem but no one has a laymans terms answer or even a proper solutions.

I have a form that uses ajax to submit the form and automati

相关标签:
4条回答
  • 2020-12-18 12:08

    It happened to me that "application.js" was stored twice (.../public/assets/application.js and .../app/assets/javascripts/application.js). The Rails 3.2.1 Asset pipeline compiled it and created another one. Check for that and delete the unneeded.

    Keep in mind that you might already have other repeated assets, you just started noticing this one because jQuery made it evident.

    This link helped me:

    http://www.ruby.code-experiments.com/blog/2011/10/another-gotcha-with-the-rails-31-asset-pipeline-or-why-are-my-jquery-ujs-ajax-requests-triggered-twi.html

    0 讨论(0)
  • 2020-12-18 12:09

    make sure that you have submit buttons disabled after the click on them. it helps to localize the problem.

      $("form").submit(function(){
        $('input[type=submit]').attr('disabled', 'disabled');
      });
    
    0 讨论(0)
  • 2020-12-18 12:11

    I had the same problem on Rails 4. I had these settings in my development.rb:

    config.assets.digest = true
    config.assets.enabled = true

    I deleted these and ran rake assets:clean

    Now its submits like it should.

    0 讨论(0)
  • 2020-12-18 12:14

    On Rails 5, rails-ujs replaces jquery_ujs. Events will trigger twice if both are required

    ```

    // app/assets/javascripts/application.js

    //= require jquery_ujs <-- delete this

    //= require rails-ujs

    ```

    0 讨论(0)
提交回复
热议问题