Rails 3.1资产-开发中的奇怪服务 [英] Rails 3.1 Assets - Strange Serving in Development
问题描述
我遇到了Rails 3.1资产管道的问题. 资产在开发中包含两次:
I've got a problem with Rails 3.1 assets pipeline. Assets are included twice in development:
<script src="/assets/main_new.js?body=1" type="text/javascript"></script>
<script src="/assets/pagenav.js?body=1" type="text/javascript"></script>
<script src="/assets/tours.controller.js?body=1" type="text/javascript"></script>
<script src="/assets/tours.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
以某种方式编译并包含 application.js ,因此所有脚本都包含两次-作为单个文件并包含在 application.js
Rails somehow compiles and includes application.js so all the scripts are included twice - as individual file and in application.js
使用预编译的生产设备,一切都很好.
Everything's fine with precompiled assets in production.
development.rb
config.assets.compress = false
config.assets.debug = true
production.rb
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress both stylesheets and JavaScripts
config.assets.compress = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :scss
config.assets.compile = false
config.assets.digest = true
application.rb
config.assets.enabled = true
推荐答案
尝试将以下内容添加到development.rb:
Try adding the following to development.rb:
config.serve_static_assets = false
...,然后清除浏览器缓存(基于注释进行更新)
...and then clearing your browser cache (update based on comments)
静态资产是指公共/资产中的预编译资产,这是rake assets:precompile
放置它们的地方.
The static assets refer to precompiled assets in public/assets, which is where rake assets:precompile
puts them.
正在发生的事情是,如果您提供公共/资产中存在的任何内容,它们将覆盖应用程序/资产中的所有内容.因此,当js标签打算识别app/assets/application.js时,将加载public/assets/application.js.
What's happening is that anything that exists in public/assets will override anything in app/assets if you are serving them. So public/assets/application.js is being loaded when the js tag is intending to identifiy app/assets/application.js.
这篇关于Rails 3.1资产-开发中的奇怪服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!