Posts Tagged coffeescript

Turbolinks trouble in Rails 4

Turbolinks is an excellent concept that was introduced into Rails 4. … hmmm whatever. It just turns the entire Rails app into an big Ajax page. All it does is this, when ever you click on  a link it sends an ajax request to the action specified, gets the content and populates it between the body tags.

Well, there is a catch, when the DOM elements are populated between the body tags lets say you have a jQuery like this

$ ->

  Some stuff here .......

The problem is the some stuff here will not be executed, as the document does not get fully loaded, to avoid it, just chanhge you code as follows

$(document).on "ready, page:change", ->

  Some stuff here .......

And all should work well!


, , ,

Leave a comment