Using Rails 3.1, where do you put your “page specific” JavaScript code?

The Asset Pipeline docs suggest how to do controller-specific JS: For example, if a ProjectsController is generated, there will be a new file at app/assets/javascripts/projects.js.coffee and another at app/assets/stylesheets/projects.css.scss. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these … Read more

Rails 4: how to use $(document).ready() with turbo-links

Here’s what I do… CoffeeScript: ready = -> …your coffeescript goes here… $(document).ready(ready) $(document).on(‘page:load’, ready) last line listens for page load which is what turbo links will trigger. Edit…adding Javascript version (per request): var ready; ready = function() { …your javascript goes here… }; $(document).ready(ready); $(document).on(‘page:load’, ready); Edit 2…For Rails 5 (Turbolinks 5) page:load becomes … Read more