Created
July 27, 2017 15:36
-
-
Save DmytroLukianov/0ab30751a57fc98fad7fd61568fb860a to your computer and use it in GitHub Desktop.
Rails console for capistrano and rbenv
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 "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