從Capfile
或config/deploy.rb
刪除load 'deploy/assets'
,並添加以下行config/deploy.rb
:
set :assets_role, [ :web, :app ]
set :normalize_asset_timestamps, false
set :assets_tar_path, "#{release_name}-assets.tar.gz"
before "deploy:update" do
run_locally "rake assets:precompile"
run_locally "cd public; tar czf #{Dir.tmpdir}/#{assets_tar_path} assets"
end
before "deploy:finalize_update", :roles => assets_role, :except => { :no_release => true } do
upload "#{Dir.tmpdir}/#{assets_tar_path}", "#{shared_path}/#{assets_tar_path}"
run "cd #{shared_path}; /bin/tar xzf #{assets_tar_path}"
run "/bin/ln -s #{shared_path}/assets #{release_path}/public"
run "/bin/rm #{shared_path}/#{assets_tar_path}"
end
如果使用turbo-sprockets-rails3,這增加了最後一塊:
run "cd #{release_path}; #{rake} assets:clean_expired 2> /dev/null"
這聽起來像一個合理的方法:) – thanikkal