Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting started with byebug in Rails

I am making my way from Django to Rails. So far I just created a new Rails app and found in the Gemfile this line:

  # Call 'debugger' anywhere in the code to stop execution and get a
  # debugger console
  gem 'byebug'

How this supposed to work? Is it as straightforward as it said in the comment? I can put debugger somewhere in code and get a debugger console in my browser?

like image 362
Dope Man Avatar asked Feb 10 '23 14:02

Dope Man


1 Answers

start rails server

rails s

and monitor the logs.

enter image description here

Now try accessing the page which points to the place where debugger is written in the code The log will stop at a point where you have put the debugger/byebug word.

enter image description here You can print out variables at that instant

update for rails 4

On suggestion of Deivid, I would like to quote him here

drop the --debug flag. You don't need to do anything special to make byebug work in Rails 4. Just require 'byebug' and call byebug

like image 189
aelor Avatar answered Feb 14 '23 09:02

aelor