捆绑程序如何处理 Rails 3.1 中的 :assets 组?

发布于 2024-12-03 12:08:58 字数 178 浏览 0 评论 0原文

我不明白这个组到底发生了什么,以及捆绑器正在用它做什么。它只在开发模式下加载吗?如果我想创建一个新的环境类型,我应该如何处理这个组? ETC。

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

还不是爱你 2024-12-10 12:08:58

处理 :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

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
一张白纸 2024-12-10 12:08:58

要详细说明答案,请参阅 rails 资产管道指南

a)默认情况下,它们不包含在生产中:

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

b)如果添加新的环境类型,您将需要根据上面德米特里的回答来处理它。也就是说,将其添加为需要它的组之一。

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.

瑕疵 2024-12-10 12:08:58

我认为应该是,

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)))

希望这有帮助:)-

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 :)-

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文