简体   繁体   中英

application.js not loading in Development (Uncaught ReferenceError: $ is not defined)

Last week i was working with starting a new Ruby on Rails Application was going to build it in Rails 4 but had many complications so i uninstalled the rvm version of rails

now one of my rails 3 project is having issues loading assets. (others are fine)

I have uninstalled all rubies and started fresh and have everything back except for my assets

Started GET "/assets/application.js?body=1" for 192.168.1.184 at 2015-03-09 14:14:22 -0500
2015-03-09 14:14:22 INFO -- Served asset /application.js - 304 Not Modified (0ms)
[2015-03-09 14:14:22] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2015-03-09 14:14:22] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2015-03-09 14:14:22] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2015-03-09 14:14:22] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2015-03-09 14:14:22] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
2015-03-09 14:14:23 INFO -- 

Console log

Uncaught ReferenceError: $ is not defined

application.js

//= require jquery
//= require jquery.geocomplete
//= require twitter/bootstrap
//= require autocomplete-rails
//= require jgrowl
//= require underscore
//= require gmaps/google
//= require rails.validations
//= require_tree .
//= require jquery_ujs
//= require jquery.ui.all
//= require amazingslider
//= require initslider-1
//= require dataTables/jquery.dataTables

Gemfile

source 'https://rubygems.org'


group :development do
  gem "bullet", '~> 4.4.0'
  gem "spring"

  gem 'rails_best_practices'
end

group :test do

  gem 'selenium-webdriver' #used for capybara features where js => true
  gem 'rspec'
  gem 'rspec-rails'
  gem 'watchr'
  gem 'launchy'
  gem 'factory_girl_rails'
  gem 'shoulda-matchers'
  gem 'capybara', '2.2.0'
  gem 'database_cleaner'
  gem 'faker'
  gem 'guard-rspec'
  gem 'guard-spork'
  gem 'spork'
  gem 'resque_spec'
  #These are for mac only
  gem 'rb-fsevent'
  gem 'cucumber-rails', :require => false
end
group :production do
  gem 'god', '0.13.1'
  gem 'whenever'
  gem 'gauges-rails'

end

gem 'client_side_validations', '3.2.5'
gem 'tzip'
gem 'i18n'
gem 'json'
gem 'rails', '3.2.3'
gem 'rake', '0.9.2.2'
gem 'will_paginate', '3.0.4'
gem 'devise', "2.1.2"
gem 'devise-encryptable', "0.1.1"
gem 'cancan'
gem 'httparty'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg', '0.15.1'
gem 'rgeo', '0.3.20'
gem 'activerecord-postgis-adapter', '0.6.3'
gem 'rgeo-geojson', '0.2.3'
gem 'rgeo-activerecord', '0.5.0'

# Gems used only for assets and not required
# in production environments by default.
gem 'twitter-bootstrap-rails', '~> 2.2.8'

gem 'rails3-jquery-autocomplete'
gem 'twitter_bootstrap_form_for'
gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'

gem 'will_paginate-bootstrap', '0.2.2'
gem 'haml'
gem 'less-rails'

# only Jquery
gem 'jquery-rails', '~> 2.1.3'
#---added----
gem 'jquery-ui-themes'
gem 'jquery-ui-rails'



gem 'mechanize'
gem 'chronic', '~>0.7.0'
gem 'resque', '~> 1.21.0', :require => 'resque/server'
gem 'redis', '3.0.1'
gem 'ruby-gmail'
gem 'mime'
gem 'roo'
gem 'pony'
#dont think we even need Mysql2 Gem since using postgres
#gem 'mysql2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'uglifier', '>= 1.0.3'

# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Deploy with Capistrano
gem 'capistrano', '2.14.2'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

#Austin Added new relic gem for newrelic.com monitoring of transactions and database'
#gem 'newrelic_rpm'

#gems for paypal sdk
gem 'paypal-sdk-rest'
gem 'paypal-sdk-merchant'
gem 'paypal-recurring'

gem 'credit_card_validations'

#PDF Generation of invoices
gem 'prawn'
gem 'levenshtein'
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
platforms :ruby do
  group :development do

    #Austin added better errors for development display of errors
    gem 'better_errors'

    #Austin added binding of caller for development in order to enable REPL and local instance variable inspection of variables on errors
    gem 'binding_of_caller'
  end

  # Use unicorn as the app server

  gem 'therubyracer', '~> 0.10.2'
  gem 'unicorn', '~> 4.6.2'
  gem 'libv8', '3.3.10.4'
  gem 'iconv'
end
gem 'recurly', '2.1.8'
gem 'sitemap_generator'
gem 'google-analytics-rails'
gem 'gmaps4rails'
gem 'feedjira'

As per the nature of this kind of problem, I can't fix it for you, but I can give you a list of things to verify that are very likely to be where the problem comes from.

  • Possible scenario is that a script tag contains calls to jQuery before the application.js file is loaded. Check in your HTML (including template) where is located the loading application.js, and verify is any call to $ is done before it
  • Another scenario is that you are loading several manifest and another manifest is calling to jQuery and is also loaded before application.js. Check on this in your HTML files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM