我需要在本地机器上预编译资产,并在使用capistrano进行部署后使用预编译的资产进行部署。
我已经添加到development.rb中
config.assets.prefix = "/dev-assets"此外,我还添加了application.rb
config.assets.initialize_on_precompile = false而不是手动执行rake assets:precompile,我想让这个过程从capistrano文件自动化,干净的资产,upload...etc。我已经尝试使用此自定义任务
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在本地和上传后预编译资源?
发布于 2013-01-05 01:52:43
问题已修复:
这是我的自定义任务运行良好:
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("rm -rf public/assets/*")
run_locally "bundle exec rake assets:precompile"
find_servers_for_task(current_task).each do |server|
run_locally "rsync -vr --exclude='.DS_Store' public/assets #{user}@#{server.host}:#{shared_path}/"
end
else
puts.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end发布于 2013-01-05 00:51:42
看起来else块中的logger.info才是问题所在。
如果您出于其他原因需要Capistrano中的记录器,则可能需要手动对其进行初始化,因为您实际上并未在服务器中运行。但是,直接打印到控制台可能更容易(就像您处理上面的其他消息一样
替换
logger.info "Skipping ..."使用
puts "Skipping ..."https://stackoverflow.com/questions/14161232
复制相似问题