Hey, I’m Parker.

Creator of music, photography, and (mostly open) software.

Launching a Rails Console With Capistrano

If you're using the popular Capistrano web deployment framework, you will likely have wished you had an easy way to perform a quick task in the production rails console on one of your servers. Many thanks to @colszowka for this solution:

NOTE: This is for Capistrano v2. Things are different for v3.

namespace :rails do
desc "Remote console"
task :console, :roles => :app do
run_interactively "bundle exec rails console #{rails_env}"
end
desc "Remote dbconsole"
task :dbconsole, :roles => :app do
run_interactively "bundle exec rails dbconsole #{rails_env}"
end
end
def run_interactively(command, server=nil)
server ||= find_servers_for_task(current_task).first
exec %Q(ssh #{server.host} -t 'cd #{current_path} && #{command}')
end

And, vòila! Run cap rails:console and you're in business.