0

I need precompile assets on my local machine and after make deploy with capistrano with assets precompiled.

I have added to development.rb:

config.assets.prefix = "/dev-assets"

also, I have added to application.rb

config.assets.initialize_on_precompile = false

Instead execute rake assets:precompile manually, I want make this process from capistrano file automated, clean assets, upload...etc. I have tried with this custom task

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

But I get a error:

/config/deploy.rb:73:in `block (3 levels) in load': undefined method `[]' for nil:NilClass (NoMethodError)

How can I precompile assets on local and after upload with 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

It looks like the logger.info in the else block is the issue.

If you need a logger in Capistrano for other reasons, you may need to initialize it manually because your not actually running in the server. But it might be easier to just print to the console (as you're doing with your other messages above

Replace

logger.info "Skipping ..."

with

puts "Skipping ..."
于 2013-01-04T16:51:42.070 に答える