我需要在我的本地机器上预编译资产,然后使用 capistrano 进行部署并预编译资产。
我已添加到development.rb
:
config.assets.prefix = "/dev-assets"
另外,我已经添加到application.rb
config.assets.initialize_on_precompile = false
而是rake assets:precompile
手动执行,我想从 capistrano 文件中自动执行此过程,清理资产,上传......等。我已经尝试过这个自定义任务
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run_locally "bundle exec rake assets:precompile"
run_locally "rsync -zvrh --progress -e 'ssh -i #{ssh_options[:keys][0]}' public/assets #{user}{server}:#{shared_path}"
puts "cleaning up locally compiled assets"
run_locally "bundle exec rake assets:clean"
else
puts "Skipping asset pre-compilation because there were no asset changes"
end
end
end
但我得到一个错误:
/config/deploy.rb:73:in `block (3 levels) in load': undefined method `[]' for nil:NilClass (NoMethodError)
如何在本地和使用 capistrano 上传后预编译资产?