如何使用capistrano访问rails控制台?

时间:2017-12-27 13:16:11

标签: ruby-on-rails ruby capistrano

我想访问远程服务器的rails控制台。 Rails版本:5.1.4 Ruby版本:2.4.3

我已尝试安装gem https://github.com/ydkn/capistrano-rails-console 我按照说明操作,但是当我“盖上生产轨道:控制台”时出现错误:

(Backtrace restricted to imported tasks)
cap aborted!
Don't know how to build task 'console' (see --tasks)

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

这是Capfile:https://pastebin.com/uNdBuTan /这是deploy.rb文件:https://pastebin.com/W8ic92Nf

2 个答案:

答案 0 :(得分:1)

通过在deploy.rb

中添加以下行,我遇到了同样的问题
namespace :rails do
 desc "Open the rails console on one remote server"
 task :console, :roles => :app do
   hostname = find_servers_for_task(current_task).first
   port = exists?(:port) ? fetch(:port) : 22
   exec "ssh -l #{user} #{hostname} -p #{port} -t 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'"
 end
end

确保在托管服务器上打开 ssh port

答案 1 :(得分:0)

检查这个宝石: