Rails 5 - turbolinks 5,some JS not loaded on page render

前端 未结 7 1053

I have a Rails app, I recently updated to 5.0.0.RC1. Most of the transition went smooth, but I\'m having some trouble with the new Turbolinks. In my app I for e

相关标签:
7条回答
  • 2020-12-30 09:06

    I tried to solve this myself and found a solution that works for me.

    My problem was that i had a forum with a "quote" functionality for comments. With turbolinks 5 i got several event listeners and ended up with up to four quotes from the same comment in my editor.

    I read upon idempotence and found a solution here: How to make jQuery `bind` or `on` event handlers idempotent

    I created (copied really) a global function that i use in my globals.coffee file for events.

    $.fn.event = (name, fn) ->
      @unbind(name).bind name, fn
    

    And it works.

    My functions looks like this:

    $('.quote').event 'click', (event) ->
     do something 
    

    All creds for this goes to: Pointy who delivered the solution.

    Link to turbolinks and idempotence

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