capistrano3:不知道如何构建任务 'deploy:create_db'

capistrano3: Don't know how to build task 'deploy:create_db'

我使用 capistrano3 部署我的 rails 应用程序。

deploy.rb

namespace :deploy do
  after "deploy", "deploy:create_db"
  after "deploy", "deploy:migrate"
  after "finishing", "deploy:restart"

  task :restart do
    on roles(:web) do
        execute "mkdir -p #{current_path}/tmp"
        execute "touch #{current_path}/tmp/restart.txt"
    end
  end

  task :create_db do
    on roles(:web) do
      execute "cd #{current_path}; bundle exec rake db:create RAILS_ENV=#{rails_env}"
    end
  end

end

当我运行cap -T时,出现如下错误:

(Backtrace restricted to imported tasks)
cap aborted!
Don't know how to build task 'deploy:create_db'

(See full trace by running task with --trace)

cap -T --trace

** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
Don't know how to build task 'deploy:create_db'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task_manager.rb:62:in `[]'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:353:in `[]'
/Library/Ruby/Gems/2.0.0/gems/capistrano-3.3.5/lib/capistrano/dsl/task_enhancements.rb:12:in `after'
/Users/liuxingqi/Public/Spar/config/deploy.rb:53:in `block in <top (required)>'

希望有人能帮助我,在此先感谢!!!

我认为你应该先定义任务...

试试这个:

namespace :deploy do

  task :restart do
    on roles(:web) do
      execute "mkdir -p #{current_path}/tmp"
      execute "touch #{current_path}/tmp/restart.txt"
    end
  end

  task :create_db do
    on roles(:web) do
      execute "cd #{current_path}; bundle exec rake db:create RAILS_ENV=#{rails_env}"
    end
  end

  after "deploy", "deploy:create_db"
  after "deploy", "deploy:migrate"
  after "finishing", "deploy:restart"
end