简体   繁体   English

Rails没有预编译javascript

[英]Rails is not precompiling javascripts

I just started a working on an existing project and I'm running into some problems with getting jquery to load on localhost. 我刚刚开始处理现有项目,但是在将jQuery加载到localhost时遇到了一些问题。 The deployed site seems to be working fine so I'm kind of stumped as to where to start to troubleshoot this issue. 部署的站点似乎运行良好,因此对于从何处开始解决此问题感到有些困惑。

In the console I'm getting: 在控制台中,我得到:

Uncaught ReferenceError: $ is not defined localhost 未捕获的ReferenceError:$未定义localhost

It seems like jquery isn't loading, but it is included in the gemfile. 看来jquery没有加载,但是它包含在gemfile中。

In the console the base.js file shows up like this: 在控制台中,base.js文件显示如下:

//= require jquery
//= require sass-bootstrap-3/dist/js/bootstrap
//= require modernizr
//= require respond
//= require lodash
;

Where I think it should be showing the complied version of the scripts. 我认为应该显示脚本的编译版本。

Running this in the console shows that jquery is indeed there. 在控制台中运行此命令表明确实存在jquery。

Rails.application.config.assets

--- !omap
- :enabled: true
- :paths:
  - /Users/000/app/assets/ebooks
  - /Users/000/app/assets/fonts
  - /Users/000/app/assets/images
  - /Users/000/app/assets/javascripts
  - /Users/000/app/assets/stylesheets
  - /Users/000/vendor/assets/javascripts
  - /Users/000/vendor/assets/stylesheets
  - /Users/000/.gem/ruby/2.0.0/gems/client_side_validations-3.2.6/vendor/assets/javascripts
  - /Users/000/.gem/ruby/2.0.0/gems/coffee-rails-3.2.2/lib/assets/javascripts
  - /Users/000/.gem/ruby/2.0.0/gems/jquery-rails-3.0.4/vendor/assets/javascripts
  - !ruby/object:Pathname
    path: /Users/000/app/assets/fonts
- :precompile:
  - !ruby/object:Proc {}
  - !ruby/regexp /(?:\/|\\|\A)application\.(css|js)$/
  - !ruby/regexp /(^[^_\/]|\/[^_])[^\/]*$/
  - !ruby/regexp /\.(?:svg|eot|woff|ttf)$/
- :prefix: /assets
- :version: '1.0'
- :debug: true
- :compile: true
- :digest: false
- :manifest:
- :cache_store:
  - :file_store
  - /Users/000/tmp/cache/assets/
- :js_compressor:
- :css_compressor: !ruby/object:Sass::Rails::CssCompressor
    options:
      :style: :compressed
- :initialize_on_precompile: true
- :logger:
- :compress: true
- :digests: {}
- :source_digests: {}

I'm using Rails 3.2.5 and jquery-rails 3.0.4. 我正在使用Rails 3.2.5和jquery-rails 3.0.4。 Any ideas on where to start troubleshooting this? 关于从哪里开始进行故障排除的任何想法? I've already spent a day trying to solve this (probably very simple fix). 我已经花了一天时间尝试解决此问题(可能是非常简单的修复)。

Did you also try http://guides.rubyonrails.org/v3.2.19/asset_pipeline.html#precompiling-assets ? 您是否也尝试过http://guides.rubyonrails.org/v3.2.19/asset_pipeline.html#precompiling-assets It might help to check your settings on precompiling assets. 检查您在预编译资产上的设置可能会有所帮助。

Beyond that, could it be that you are missing the line //= require jquery_ujs ? 除此之外,是否可能是您缺少这一行//= require jquery_ujs https://github.com/rails/jquery-rails specifies both //= require jquery and //= require jquery_ujs . https://github.com/rails/jquery-rails同时指定//= require jquery//= require jquery_ujs

This was solved by doing two things: 这可以通过做两件事来解决:

first: downgrade to ruby 1.9.3 and second: as was suggested above, add //= require jquery_ujs to the manifest js file 第一个:降级为ruby 1.9.3,第二个:如上述建议,将//= require jquery_ujs添加到清单js文件中

Thanks for your help. 谢谢你的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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