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
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