RubyMineでRailsデバッグ環境構築

概要

RubyMineでRailsデバッグ環境を構築する手順です。

Windows7VirtualBoxVagrantRuby + Rails4 開発環境の構築【初心者必見】 - Qiitaの記事を参考にしています。

  1. Railsの環境構築
  2. RubyMineによるRailsデバッグ環境構築

Railsの環境構築

以下の手順でRailsアプリをホスト側のブラウザで表示することができます。

  1. 仮想環境構築
  2. Railsアプリ環境構築
  3. Railsアプリ実行

参考情報

仮想環境構築

仮想環境は、VirtualBox/vagrantで行いました。

  • VirtaulBoxインストール
  • vagrantインストール
  • OSインストール
  • Centos6.5をインストールしました。

Railsアプリ環境構築

Railsアプリ実行

Railsアプリがホスト側のブラウザに表示されなかったので、起動オプションを追加しました。

RubyMineによるRailsデバッグ環境構築

  1. ruby-debug-ideのインストール
  2. sampleアプリの起動
  3. RubyMineの設定
  4. デバッグ実行

ruby-debug-ideのインストール(リモート側)

デバッグ用gemを追加します。

$ cd /vagrant/sample
$ vi Gemfile
gem 'ruby-debug-ide'
gem 'debase'

$ bundle install

sampleアプリの起動

デバッグ待ち状態になります。

$ cd /vagrant/sample
$ rdebug-ide --port 1234 --dispatcher-port 26162 --h 0.0.0.0 -- bin/rails s -b 0.0.0.0

RubyMineの設定

Run-Edit ConfigurationsでRuby remote debugを追加。remote root folderとlocal root folderを設定する。Server commandをsampleアプリ起動コマンドと合っていることを確認します。

デバッグ実行

ブレイクポイントを設定して、RubyMineでRun-Debug xxxを実行します。リモートでRailsアプリが起動します。

ブレイクポイントで停止すれば成功です。

「Getting undefined method for nil:NilClass」というエラーがブラウザに表示された場合には、byebugというgemをコメントアウトするとうまくいくかもしれません。

$ cat Gemfile
group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  #gem 'byebug'
f:id:unokun3:20150822133043p:plain