undefined方法`[]'为nil:资产期间的NilClass:在使用capistrano部署时预编译rake

问题描述 投票:1回答:1

我已经配置了capistrano,以便当我通过capistrano运行部署时,资产在生产时编译。我使用Ruby 1.9.3,Rails 3.2.13与MongoDb数据库。问题仅在部署期间存在,在开发和生产方面我都可以手动编译资产而没有任何问题

desc "Update the deployed code."
task :update_code, :except => { :no_release => true } do
  run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"
  finalize_update
  assets.precompile
end

namespace :assets do
  desc "Assets precompileing"
  task :precompile, :roles => :web, :except => { :no_release => true } do
    run "cd #{current_path}; rm -rf public/assets/*"
    run "cd #{current_path}; bundle exec rake RAILS_ENV=#{rails_env} assets:precompile"
  end
end

但是我收到了这个错误

executing command
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby /my-app/path/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
undefined method `[]' for nil:NilClass
/my-app/path/shared/bundle/ruby/1.9.1/gems/moped-1.4.5/lib/moped/protocol/reply.rb:71:in `command_failure?'
/my-app/path/shared/bundle/ruby/1.9.1/gems/moped-1.4.5/lib/moped/node.rb:82:in `block in command'
/my-app/path/shared/bundle/ruby/1.9.1/gems/moped-1.4.5/lib/moped/node.rb:582:in `[]'
/my-app/path/shared/bundle/ruby/1.9.1/gems/moped-1.4.5/lib/moped/node.rb:582:in `block (3 levels) in flush'
/my-app/path/shared/bundle/ruby/1.9.1/gems/moped-1.4.5/lib/moped/node.rb:581:in `map'
...
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
    command finished in 14427ms
failed: "env RAILS_ENV=production sh -c 'cd /my-app/path/current; bundle exec rake RAILS_ENV=production assets:precompile'"
zlib(finalizer): the stream was freed prematurely.

所以它与资产中的任何特殊文件无关,我只使用纯.js和.css文件。

以为我使用的多个清单文件可能存在一些问题,但我添加了config.assets.precompile + = ['another-manifest.js','another-manifest.css']

如果我在部署期间关闭资产编译并在部署完成后手动执行,那么它应用于application.rb,它就像开发和生产中的魅力一样。

我还尝试只留下一个只需要自己的清单文件,但错误仍然存​​在。

Mongoid文档在qazxsw poi的提示部分讨论了类似的问题

但我目前使用1.9.3 Ruby构建p392所以它应该没问题。

任何有关这方面的帮助都会很棒!

ruby-on-rails ruby mongodb capistrano asset-pipeline
1个回答
0
投票

如果您有任何http://mongoid.org/en/mongoid/docs/tips.html助手,如asset-url等,您的样式文件必须是image-url

在纯css中使用scss帮助程序会在预编译期间出现sprockets错误并导致部署失败。

© www.soinside.com 2019 - 2024. All rights reserved.