The regular way to tell jQuery to wait until the DOM is ready is:
But this will not work in many cases in a Rails 4 app. The reason is that Turbolinks functionality is enabled by default. Instead of reloading the whole page when you navigate to a new page within your site, Turbolinks will only load the new content. The old content (your navigation bar, etc) will stay the same. So there never is a DOM ready event.
These two sites have notes about how to fix this: