2011-09-08 89 views
19

我不明白這個小組究竟發生了什麼,以及捆綁者在做什麼。它是否只在開發模式下加載?如果我想創建一個新的環境類型,我該如何處理這個組?等如何在bundles中處理rails 3.1中的資產組?

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

回答

22

,處理: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 
+4

http://stackoverflow.com/a/7675331/474597此答案解答它 – lulalala

8

要詳細一點的答案,從rails asset pipeline guide

一)在默認情況下,他們不包括在生產:

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

b)如果您添加一個新的環境類型,你會想根據德米特里的回答來處理它。也就是說,將其添加爲將需要它的一個組。

0

我覺得應該是,

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

希望這有助於:) -