https://github.com/rails/turbolinks/
because , if we use the turbolinks gem , it will make our application behave like a page javascript application .
So , if we use $(document).ready() on different page , it will not work .
how to fix it :
use gem https://github.com/kossnocorp/jquery.turbolinks
of reference
http://stackoverflow.com/questions/17600093/rails-javascript-not-loading-after-clicking-through-link-to-helper?rq=1
change code
$(document).on('page:load', function() {
// your stuff here
});
ar ready = function() {
// do stuff here.
};
$(document).ready(ready);
$(document).on('page:load', ready);
another issue : if you use turbolinks , you should put your script inside the head .
Otherwise , if you put your script inside the page body ,you will got an javascript have been loaded error
if you really need to put inside the body
do the following
http://stackoverflow.com/questions/20684846/turbolinks-causing-a-jquery-ujs-has-already-been-loaded-error
<script type="text/javascript" data-turbolinks-eval=false>
console.log("I'm only run once on the initial page load");
</script>
沒有留言:
張貼留言