How is the :assets group in rails 3.1 handled by bundler?

和自甴很熟 提交于 2019-12-30 00:52:14

问题


I don't understand what exactly is going on with this group, and what bundler is doing with it. Is it only loaded in dev mode? What if I want to make a new environment type, how should I handle this group? Etc.

group :assets do
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

回答1:


The code that handles :assets group placed in config\application.rb. In rails 3.1 it is:

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



回答2:


To elaborate a little on the answer, from rails asset pipeline guide:

a) by default they are NOT included in production:

# Gems used only for assets and not required
# in production environments by default.

b) If you add a new environment type, you would want to handle it according to Dmitry's answer above. That is, add it as one of the groups that will require it.




回答3:


I think it should be,

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

because there are some warning with the line,

Bundler.require *Rails.groups(:assets => %w(development test))

So we use,

Bundler.require(*Rails.groups(:assets => %w(development test)))

Hope this helps :)-



来源:https://stackoverflow.com/questions/7351607/how-is-the-assets-group-in-rails-3-1-handled-by-bundler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!