Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

Rails, turbolinks and javascript. How to avoid duplicate Switchery button appear?

Javascript • Asked by Lee Terng Gio

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 ?


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.