Rails, turbolinks and javascript. How to avoid duplicate Switchery button appear?
I'm implementing Switchery button in my Rails app and Turbolinks is on. When I navigate to another page, and then click the back button, the button is being duplicated.
Here is my Javascript code:
$(document).on('turbolinks:load', function() {
var elem = document.querySelector('.js-switch');
var switchery = new Switchery(elem, {className:"switchery switchery-small"});
});
Html view:
<b>Assign as administrator?<span> <%= f.check_box :admin, class:"js-switch" %></span></b>
Screenshot: ![https://i.stack.imgur.com/ePJdk.png]
So how can i handle this problem ?