0

我的 rails 项目中有 vendor.js 文件,其中包含几个供应商库,在添加一些新库后,我在开发环境中遇到了这个问题

Started GET "/assets/vendor.js" for 10.40.129.65 at 2013-03-03 14:01:24 +0400
Cache write: 0d6281da1957dd9c5e063fb636c50bd260dae5e2
Cache read: 0d6281da1957dd9c5e063fb636c50bd260dae5e2
Cache read: http://work:3000/assets/vendor.js?
Cache write: http://work:3000/assets/vendor.js?
!! Rack application returned nil body. Probably you wanted it to be an empty string?
!! Unexpected error while processing request: undefined method `each' for nil:NilClass

尝试删除一些库可以解决问题,并且预编译的资产可以正常工作。但我想让它在开发中工作。请帮帮我。

供应商.js:

//= require ./vendor/ext/stacktrace.js
//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require twitter/bootstrap
//= require js_notifier
//= require ./vendor/ext/mustache-1.4.2
//= require ./vendor/ext/strftime
//= require ./vendor/ext/moment
//= require ./vendor/ext/langs.js
//= require ./vendor/ext/jquery.jgrowl_minimized.js
//= require ./vendor/ext/jquery-ui-1.10.0.custom.min.js
//= require ./vendor/ext/jquery-ui-sliderAccess.js
//= require ./vendor/ext/jquery-ui-timepicker-addon.js
//= require ./vendor/ext/backbone.paginator.js
//= require ./vendor/ext/jquery-deparam.min.js
//= require ./vendor/ext/select2.js
//= require_tree ./templates
//= require ./vendor/channels.js.coffee
//= require ./vendor/ext/bootstrap.switch.js
//= require ./vendor/ext/private_pub
//= require ./vendor/ext/spin.js
//= require ./vendor/ext/jquery.spin.js

我正在使用 Memcached + Dalli

UPD:我已经在每个环境中明确设置了 cache_store(developemnt.rb、production.rb 和 test.rb),这解决了问题,直到我打开谷歌浏览器再次出现问题。结果,在 FF 中一切正常,Chrome 无法加载 vendor.js(相同的服务器实例(瘦)并且在同一时间用于两个浏览器)

记录 ff 请求:

Cache read: http://work:3000/assets/vendor.js?
Cache read: 577d6ed0d98975b583329c312bd25667620f2497

记录 chrome 请求(同上):

Started GET "/assets/vendor.js" for 10.40.129.65 at 2013-03-03 20:37:11 +0400
Cache write: 577d6ed0d98975b583329c312bd25667620f2497
Cache read: 577d6ed0d98975b583329c312bd25667620f2497
Cache read: http://work:3000/assets/vendor.js?
Cache write: http://work:3000/assets/vendor.js?
!! Rack application returned nil body. Probably you wanted it to be an empty string?
!! Unexpected error while processing request: undefined method `each' for nil:NilClass
4

1 回答 1

1

您可以考虑应用index.js技术,如本 Rails 指南(2.1.2) 中所述。尝试拆分您的大文件并将这些部分包含在清单文件中,例如:

在您/app/vendor/assets/javascripts创建一个新目录my_libraries并将零件放入其中。然后在同一目录中创建index.js清单文件并正常包含文件:

//= require file1
//= require file2

在你的application.js

//= require my_libraries

编辑:一种解决方案是:在您的(/vendor/ext正确的路径是css) 来创建内容:app/vendor/assets/javascripts/ext/vendor/extindex.js

//= require_tree .

并在application.js

//= require ext

然后您应该从清单中删除对vendordir 的所有引用。application.js另一个错误是在清单中包含带有.js前缀的文件。在清单文件中,您应该声明不带前缀的包含。

查看解释require_tree使用的资产管道的文档。

于 2013-03-03T10:24:01.877 回答