Rails 4,capistrano错误:无法加载此类文件 - deploy / assets

时间:2013-11-06 04:05:13

标签: ruby-on-rails deployment ruby-on-rails-4 capistrano

我一直在关注部署到VPS http://railscasts.com/episodes/335-deploying-to-a-vps的这个railscast,我似乎仍然坚持部署。当我输入cap deploy时,我明白了。

cap aborted!
cannot load such file -- deploy/assets
/files/rails/Capfile:2:in `load'
/files/rails/Capfile:2:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/capistrano-3.0.1/lib/capistrano/application.rb:22:in `load_rakefile'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/capistrano-3.0.1/lib/capistrano/application.rb:12:in `run'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/capistrano-3.0.1/bin/cap:3:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p247/bin/cap:23:in `load'
/usr/local/rvm/gems/ruby-2.0.0-p247/bin/cap:23:in `<main>'
(See full trace by running task with --trace)

我的deploy.rb

require "bundler/capistrano"

server "(removed)", :web, :app, :db, primary: true

set :application, "Fooddiscovery"
set :user, "(removed)"
set :deploy_to, "/home/rails"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "(removed)"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"

  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end
  before "deploy", "deploy:check_revision"
end

我的capfile

load 'deploy' if respond_to?(:namespace)
load 'deploy/assets'
load 'config/deploy'

我读了其他问题和答案 if respond_to?(:namespace) 它实际上帮助了第一个错误,而不是部署/资产,它用于显示刚刚部署的错误(无法加载此类文件 - 部署)。如果所有三个链接都使用respond_to?(:namespace),则无法解决问题。事实上,一个新错误显示我是否这样做告诉我未定义的局部变量或方法`tasks_without_stage_dependency'。

谢谢!

2 个答案:

答案 0 :(得分:2)

@ Michael是正确的,你正在使用Capistrano 2的Capistrano 2语法,但你可以确保你在Gemfile中使用Capistrano 2进行快速修复。

gem 'capistrano', '2.15.5'

但是如果你对使用Capistrano 3感兴趣,那么这对我来说非常好upgrade guide

答案 1 :(得分:1)

看起来您在Capfile中使用了Capistrano 2语法,并且已升级到Capistrano 3 gem。

Capistrano 3看起来更像Capfile中的以下内容

require 'capistrano/rails'