如何仅在开发环境中需要资产
我正在使用 Rails 3.1 中的资产管道,并且仅当它是开发环境时我才想包含一些 javascript 文件。
示例:
//= require application/jquery
//= require application/jquery_ujs
// next ones only for development environment
//= require application/badglobals
//= require application/consul
有这样做的标准方法吗?有什么建议吗?
更新
查看 Sprockets 当前的文档,似乎没有办法做到这一点。
I'm using the assets pipeline from Rails 3.1 and I want to include some javascript files only if it's the development environment.
Example:
//= require application/jquery
//= require application/jquery_ujs
// next ones only for development environment
//= require application/badglobals
//= require application/consul
Its there a standar way of doing this? Any suggestions?
Update
Looking at the Sprockets current documentation, seems like there is not a way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不在视图中只需要这些呢?将它们加载到资产中重要吗?要将它们加载到视图中:
Why not just require these in the view? Is it important that they are loaded in the asset? To load them in the view:
如果您将
application.js
文件(或您在其中调用//= require ...
的任何文件)重命名为application.js.erb,您可以利用
require_asset
。即:来源:https://github.com/sstephenson/sprockets/issues/90
If you rename your
application.js
file (or whichever file you're calling//= require ...
in) toapplication.js.erb
, you can take advantage ofrequire_asset
. i.e:Source: https://github.com/sstephenson/sprockets/issues/90