application.js不会将任何脚本文件加载到其中。代码如下所示。我试了几个小时,但我不知道如何解决这个问题。有人帮忙吗?
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require datepicker
//= require_tree .
;
和我的宝石文件
source 'https://rubygems.org'
gem 'rails', '~>3.1.0'
gem 'thor','>=0.14.4'
gem 'nifty-generators'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'will_paginate'
gem 'execjs'
gem 'therubyracer', :platform => :ruby
gem 'rbbcode'
gem 'carrierwave'
gem 'mini_magick'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'bootstrap-sass', '2.3.2.0'
gem 'sprockets', '~>2.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platform => :ruby
gem 'uglifier'
end
gem 'jquery-rails'
不知何故,它没有加载任何东西。我尝试预编译它们,但它显示错误
rake aborted!
ExecJS::RuntimeError:
(in c:/Ruby193/lib/ruby/gems/1.9.1/gems/jquery-rails-3.1.1/vendor/assets/javascripts/jquery.min.js)
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
我尝试了一些解决方案,例如将我的ruby从2.0.0降级到1.9.3但它不起作用。 rails版本也是3.1.0
整个--trace预编译
$ bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to s
kip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
...... C:\ Users \ WebDev \ AppData \ Local \ Temp \ execjs20140806-8216-16s9hrzjs(487,5)(null):函数不正确。
rake aborted!
ExecJS::RuntimeError:
(in c:/Ruby193/lib/ruby/gems/1.9.1/gems/jquery-rails-3.1.1/vendor/assets/javascripts/jquery.min.js)
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
答案 0 :(得分:2)
希望您在生产模式下尝试它。请使用Gemfile中的以下代码替换gem 'therubyracer', :platforms => :ruby
,
group :development do
gem 'therubyracer', :platforms => :ruby
end
并运行bundle install
。
另请参阅https://stackoverflow.com/a/16784942/1896986
希望有所帮助:)
答案 1 :(得分:1)
所以我假设您所说的application.js
文件是所有coffeescript(以及javascript)资产的连续和缩小版本,对吗?如果是这种情况,我建议运行以下命令:
rake assets:precompile RAILS_ENV=production
。
如果您仍然遇到错误,我打赌它是javascript运行时的问题 - 在这种情况下,@ Rajesh建议的解决方案似乎是一个很好的解决方案。