1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Railsでデバック binding.pryを使う

Last updated at Posted at 2021-08-07

デバックとは

プログラムのバグを手直しすること。
binding.pryを止めたい場所に挟む。

デバックの考え方

binding.pryで止まらなかった。
それより前にどこかに問題がある。

railsでbinnding.pryの導入

まずはgemのインストール
Gemfile

group :development, :test do
  gem 'pry-rails'
  gem 'pry-byebug'
end

binding.pryで処理を止める

binding.pryを挟めばok

home_controller.rb

class HomeController < ApplicationController
  def index
    binding.pry
end
end

$ bundle exec rails s

localhost:3000/homes/index のURLに入力すると処理が止まる。

使えるコマンド

next 次の行へ移動
continue プログラムの実行
step 次の行かメソッド あまり使わない
exit! 強制終了
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?