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>
Rails 以某种方式编译并包含 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)
静态资产是指public/assets中的预编译资产,这是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屋!