2011-09-06 130 views
4

试图让部署轨3.1应用程序的窍门......Rails 3.1 - 如何判断资产是否在生产中预编译?

基于我读过,我已经把下面的代码在我deploy.rb:

before "deploy:symlink", "assets:precompile" 

namespace :assets do 
    desc "Compile assets" 
    task :precompile, :roles => :app do 
    run "cd #{release_path} && rake RAILS_ENV=#{rails_env} assets:precompile" 
    end 
end 

但要告诉你事实,我不能注意到有或没有差异。有什么我在这里失踪?

编辑*找到了答案:

http://spreecommerce.com/blog

预编译生产您通常会执行以下rake任务(在生产服务器上)的资产。

$ bundle exec rake assets:precompile 这会将所有资产写入public/assets目录,同时在文件名中包含MD5指纹以增加缓存优势。

注意:在生产过程中,来自使用image_tag,asset_path,javascript_include_tag等视图的资产的所有引用都会自动将此指纹包含在文件名中,以便提供正确的版本。

回答

0

有配置要做,但应该在默认情况下正确设置。获取你的config/application.rb中,看看你是否发现这样的:

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 
... 
config.assets.enabled = true 

你也应该有那些在您production.rb文件:

# Compress JavaScripts and CSS 
config.assets.compress = true 

# Don't fallback to assets pipeline if a precompiled asset is missed 
config.assets.compile = false 

这应该是设置方式。是吗?