如何通过bundler处理rails 3.1中的:assets组?
我不明白这个组究竟发生了什么,以及捆绑器正在做什么。 它只在开发模式下加载吗? 如果我想创建一个新的环境类型,我应该如何处理这个组? 等等。
group :assets do gem 'coffee-rails', "~> 3.1.0" gem 'uglifier' end
处理的代码:assets
组放在config\application.rb
。 在rails 3.1中它是:
if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require *Rails.groups(:assets => %w(development test)) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end
从rails资产管道指南中详细说明答案:
a)默认情况下,它们不包含在生产中:
# Gems used only for assets and not required # in production environments by default.
b)如果你添加一个新的环境类型,你会想根据Dmitry的答案处理它。 也就是说,将其添加为需要它的组之一。
我认为应该是,
if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end
因为这条线有一些警告,
Bundler.require *Rails.groups(:assets => %w(development test))
所以我们用,
Bundler.require(*Rails.groups(:assets => %w(development test)))
希望这可以帮助 :)-
- 如何在Rails 2.3.5中从模型中呈现部分
- NoMethodError at / undefined方法`name’代表nil:NilClass
- 查询与activerecord的交集
- RunTimeError:ActionController :: RackDelegation在rspec 2.10.1中用于rails 3.1.4应用程序控制器
- 将emacs ruby-mode缩进更改为4个空格
- 处理非常长时间的rake任务
- Rails:通过页面刷新重置表单字段
- 如何以递归方式从(YAML)哈希中删除具有空值的所有键?
- has_many association sate check执行N + 1查询活动管理员