【问题标题】:Rails 3.1 - how can I tell if assets are precompiling on production?Rails 3.1 - 我如何判断资产是否在生产中预编译?
【发布时间】:2011-09-06 04:17:14
【问题描述】:

试图掌握部署 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

但说实话,我看不出有没有它有什么区别。我这里有什么遗漏吗?

EDIT* 找到了答案:

http://spreecommerce.com/blog

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

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

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

【问题讨论】:

    标签: deployment capistrano ruby-on-rails-3.1


    【解决方案1】:

    有配置要做,但默认情况下应该正确设置。进入你的 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
    

    应该这样设置。是吗?

    【讨论】:

      猜你喜欢
      • 2011-12-31
      • 2011-12-20
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 2013-05-08
      • 2012-05-20
      • 2012-01-02
      相关资源
      最近更新 更多