Skip to content

Instantly share code, notes, and snippets.

@DmytroLukianov
Created July 27, 2017 15:36
Show Gist options
  • Save DmytroLukianov/0ab30751a57fc98fad7fd61568fb860a to your computer and use it in GitHub Desktop.
Save DmytroLukianov/0ab30751a57fc98fad7fd61568fb860a to your computer and use it in GitHub Desktop.
Rails console for capistrano and rbenv
namespace :rails do
desc "Open the rails console"
task :console do
on roles(:app) do
rails_env = fetch(:rails_env, 'production')
execute_interactively "$HOME/.rbenv/bin/rbenv exec bundle exec rails console #{rails_env}"
end
end
desc "Open the rails dbconsole"
task :dbconsole do
on roles(:app) do
rails_env = fetch(:rails_env, 'production')
execute_interactively "$HOME/.rbenv/bin/rbenv exec bundle exec rails dbconsole #{rails_env}"
end
end
def execute_interactively(command)
user = fetch(:user)
port = fetch(:port) || 22
exec "ssh -l #{user} #{host} -p #{port} -t 'cd #{deploy_to}/current && #{command}'"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment