I have been developing a rails app for a week now. I use jquery-rails gem to use jQuery and everything was working fine. But today, when I started the development server, jQuery just wasn't loading. The console gave the error jQuery not defined and $ not defined and so forth. So I checked if the jQuery files are being included and they were. But when I clicked on the link to the jquery.js file, it contained only the following.

(function() {


}).call(this);

jQuery just isnt working..

This is how I have required the js libraries:

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require bootstrap-datepicker/core
//= require_tree .

I have tried interchanging bootstrap and jQuery and even tried removing jQuery and using only bootstrap. Nothing seems to be working.

The funny part is that it was working perfectly till last night!! And I don't remember adding or removing any js libs. I was only writing Javascript code. So I have no clue as to what went wrong overnight.

The only thing I haven't tried is serving jQuery from a CDN. But that is not an option considering where my app is going to be deployed.

Please help.

My Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.8'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'will_paginate', '~> 3.0.beta'
gem 'will_paginate-bootstrap'


#gem 'sqlite3'
gem 'mysql2'
#gem 'devise'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
    gem 'twitter-bootstrap-rails'
    gem 'less-rails'
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
gem 'bootstrap-datepicker-rails'
gem 'libv8'

Thanks in advance.

Member Avatar for LastMitch

Empty body function in jquery.js - Rails 3.2 with jquery-rails gem

Are you connected the jquery files correctly:

You have to used something like this:

<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "application", :media => "all" %>

and you can add this:

Rails.application.config.assets.paths.

You can read more about it here:

http://guides.rubyonrails.org/asset_pipeline.html

You can also read more about it here (some tips):

http://www.aloop.org/2012/06/03/tips-for-rails-asset-pipeline/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.