application.js未在开发中加载(未捕获的ReferenceError:$未定义)

时间:2015-03-09 19:12:59

标签: javascript ruby-on-rails ruby asset-pipeline

上周我正在开发一个新的Ruby on Rails应用程序,它将在Rails 4中构建它但是有很多复杂因素,所以我卸载了rvm版本的rails

现在我的一个rails 3项目在加载资产时出现问题。 (其他人都很好)

我已经卸载了所有红宝石并重新开始并且除了我的资产之外还有所有东西

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 -- 

控制台日志

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'

1 个答案:

答案 0 :(得分:1)

根据这类问题的性质,我无法为您解决此问题,但我可以为您提供一系列要验证的问题,这些问题很可能是问题的来源。

  • 可能的情况是脚本标记在加载application.js文件之前包含对jQuery的调用。检查你的HTML(包括模板)在哪里找到加载application.js,并验证对$的任何调用是否在它之前完成
  • 另一种情况是您正在加载多个清单,另一个清单正在调用jQuery,并且还在application.js之前加载。在HTML文件中查看此内容。