Reputation: 65
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?
Upvotes: 4
Views: 12407
Reputation: 11126
start rails server
rails s
and monitor the logs.
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.
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
Upvotes: 6
Reputation: 84182
You won't get a debugger in your browser - calling debugger
or byebug
will drop you into the byebug prompt in the terminal window that was used to run your rails server (note that this is not the same as the rails console - there is a overview of what you can do in the rails debugging guide).
Another tool you may be interested in is the web-console gem (included by default in rails 4.2 and above). This allows you call console
(in a controller, view etc.) and will dump you into a browser based IRB session at that point
Upvotes: 2