Voici comment écrire une “recipe” Capistrano qui vous permettra d’ouvrir une console Rails depuis votre machine locale.
Créez le fichier lib/capistrano/tasks/rails.rake
et y copier/coller ceci:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :rails do | |
desc 'Remote console' | |
task :console do | |
on roles(:app) do |h| | |
command = 'rails console' | |
run_interactively "RAILS_ENV=#{fetch(:rails_env)} bundle exec #{command}", | |
h.user | |
end | |
end | |
desc 'Remote dbconsole' | |
task :dbconsole do | |
on roles(:app) do |h| | |
command = 'rails dbconsole' | |
run_interactively "RAILS_ENV=#{fetch(:rails_env)} bundle exec #{command}", | |
h.user | |
end | |
end | |
end | |
def run_interactively(command, user) | |
info "Connecting with #{user}@#{host}:#{fetch(:deploy_to)}/current" | |
cmd = "ssh #{user}@#{host} -t 'cd #{fetch(:deploy_to)}/current && " \ | |
'PATH=/home/triggr/.rbenv/shims:/home/triggr/.rbenv/bin:$PATH ' \ | |
"#{command}'" | |
exec cmd | |
end |
Maintenant vous pouvez faire cap staging rails:console
et vous avez une console en staging :)