Rails 3.1 - 如何判断资产是否在生产中进行预编译?

问题描述 投票:4回答:1

试图摆脱部署rails 3.1 App ...

根据我读过的内容,我将以下代码放在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等对视图中的资产的所有引用都将自动在文件名中包含此指纹,以便提供正确的版本。

deployment capistrano ruby-on-rails-3.1
1个回答
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

应该这样设置。 是吗?

© www.soinside.com 2019 - 2024. All rights reserved.