0

我需要在我的本地机器上预编译资产,然后使用 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 上传后预编译资产?

4

2 回答 2

2

问题已解决:

这是我的自定义任务工作正常:

 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-04T17:52:43.127 回答
0

看起来问题是logger.infoelse块中。

如果您出于其他原因需要Capistrano 中的记录器,则可能需要手动初始化它,因为您实际上并未在服务器中运行。但是只打印到控制台可能会更容易(就像您对上面的其他消息所做的那样

代替

logger.info "Skipping ..."

puts "Skipping ..."
于 2013-01-04T16:51:42.070 回答