Rails 4: how to use $(document).ready() with turbo-links
pI ran into an issue in my Rails 4 app while trying to organize JS files
the rails way. They were previously scattered across different views. I
organized them into separate files and compile them with the assets
pipeline. However, I just learned that jQuery's ready event doesn't fire
on subsequent clicks when turbo-linking is turned on. The first time you
load a page it works. But when you click a link, anything inside the
codeready( fucntion($) {/code won't get executed (because the page doesn't
actually load again). Good explanation: a
href=http://stackoverflow.com/questions/18769109/rails-4-turbo-link-error-uncaught-typeerror-cannot-read-property-position-of/18770219?noredirect=1#18770219here/a./p
pSo my question is: What is the right way to ensure that jquery events
work properly while turbo-links are on? Do you wrap the scripts in a
Rails-specific listener? Or maybe rails has some magic that makes it
unnecessary? The docs are a bit vague on how this should work, especially
with respect to loading multiple files via the manifest(s) like
application.js./p
No comments:
Post a Comment