LoginSignup
9
7

More than 3 years have passed since last update.

ローカルのターミナルから本番環境のリモートサーバーにrails consle(rails c)する

Posted at

はじめに

本番環境のリモートサーバーでrails consoleしたい時に便利です

Capistranoでデプロイしている前提です

capistrano-rails-consoleというgemを使います

Gemを追加

Gemfileの一番下にcapistrano-rails-consoleを追記します

Gemfile
group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'capistrano'
  gem 'capistrano-rbenv'
  gem 'capistrano-bundler'
  gem 'capistrano-rails'
  gem 'capistrano3-unicorn'
  #以下を追記
  gem 'capistrano-rails-console'
end

bundle installします

ターミナル
bundle install

Capfileの編集

Capfileに以下を追記します

Capfile
~省略~
require 'capistrano/rails/console'
~省略~

保存したらbundle exec cap production deployコマンドでデプロイします

rails consoleする

デプロイが完了したら、ローカルのターミナルでアプリケーションのディレクトリに移動して以下のコマンドを打ちます

ターミナル
bundle exec cap production rails:console

これでローカルのターミナルで、本番環境のリモートサーバーにrails cできるようになりました

間違ってdestroy_allとかしないようにご注意を・・

以上で終了です:v:

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7