Brian Joseph Spinos Brian Joseph Spinos - 1 year ago 78
Javascript Question

How can I use Jquery in rails 3.2.8?

All the tutorials I've read tell me to use the "public/javascripts" folder. But there is no such folder in rails 3.2.8

  • where do I place my jquery code?

  • isn't Jquery included in Rails 3.2.8?

Answer Source

The default Rails application (> 3.2) includes the jQuery gem on line 23 of the Gemfile:

gem 'jquery-rails'

You place your jQuery code in a custom JavaScript file--e.g., hello.js--in the following path:




In hello.js, make sure you include your jQuery code inside of this block:

$(document).ready(function() {

That's it. You're ready to use jQuery in Rails. (This works because of line 15 in app/assets/javascripts/application.js)

//= require_tree .

This line says to include everything in the javascripts directory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download