The default Rails application (> 3.2) includes the jQuery pearl in line 23 of the Gemfile:
gem 'jquery-rails'
You put jQuery code in a custom JavaScript file - for example, hello.js - in the following way:
app/assets/javascripts/
Example:
app/assets/javascripts/hello.js
In hello.js make sure you include jQuery code inside this block:
$(document).ready(function() { YOUR CODE HERE });
What is it. Are you ready to use jQuery in Rails. (This works because of line 15 in app/assets/javascripts/application.js )
This line talks about including everything in the javascripts directory.
source share