Rails 4 Turbolinks make form submit multiple times

后端 未结 3 844
迷失自我
迷失自我 2020-12-10 08:03

I use some code working nicely on Rails 3 but not on Rails 4, I guess it is caused by Turbolinks but I don\'t know much about it, can\'t dig more deep to solve my problem, h

3条回答
  •  佛祖请我去吃肉
    2020-12-10 08:51

    You can leave it in the body, you just need to add to your script tag:

    "data-turbolinks-eval" => false
    

    In general, with turbolinks, it's best to make sure your code is "idempotent", so if it runs more than once, bindings won't get setup more than once.

    The best way to do this is instead of $('blah').bind(), call unbind first:

     $('blah').unbind('click').bind('click', function() {
    

提交回复
热议问题