Looking at your question, I am wondering what this raty() method does. It seems more that the problem is there, not in Turbolinks. If your script does not set up a listener that can deal with being loaded once only, and responding to events, then it's probably not a good peer to Turbolinks.
Generally speaking, if you need to do something to the page at each load, you can change your load event to turbolinks:load. But more likely, if you refactor your method to this pattern, you won't care.
Instead of this:
$('.rating').click(function(){
$(this).whatever...
});
Do this:
$(document).on('.rating', 'click', function(){
$(this).whatever...
});
That will fire on every click, but only get past the first line if the click was on a .rating classed element, and then look deeper and do its thing. You don't have to re-attach this listener to the DOM at each page load, because it lives at a level where it can deal with the changes Turbolinks makes to the DOM beneath it.
Walter
> On Oct 11, 2016, at 6:42 PM, Emmanuel Mtali <emmanuelmtalig@gmail.com> wrote:
>
> I recent posted a question on StackOverflow but sadly i dint get enough attention. My question is "Can someone please tell me how can i handle problems introduced by Turbolinks on handling JavaScript??? , or i should stop using it(turbolinks)?? " Thanks,
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/06ca2e36-1e16-46f1-aac6-c6d47b106dad%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/82D0EBDF-B0DD-4BB8-9DE4-0531DA1F8D8C%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment