Setting breakpoints in Rails
April 15th, 2006
In order to understand what was going on with the Amazon sidebar component, I found it necessary to set a breakpoint and examine the some variables. Let's take a look at how Ruby on Rails lets you set breakpoints and what you can do with them.
In my meatspace copy of Agile Web Development with Rails, page 196 is where I found the directions for what to do. Here's what I did:
I opened the amazon_controller.rb code file down in typo\components\plugins\sidebars. In this file, I was really puzzled by this bit of code:
So, I typed breakpoint() on the line just above this line, saved the file and then I started the WEBBrick server.
Also, following the instructions in the Agile book, I opened a command prompt in the typo directory and ran this command:
ruby script/breakpointer
And I left the console window open. I've found that if you have a breakpoint in your development code and you don't run this breakpointer script, execution of your app will halt anyway. Just run the script or delete your breakpoint. Then I started the web app and very quickly the breakpointer showed some stuff and paused in an irb prompt. From here I was able to examine all of the various parts of that line of code.
It's hard to see in the image above, but I had just typed params[:contents] at the irb prompt and all the stuff on the screen is the output of that.
When you're done with one breakpoint, just type 'exit' to leave irb and execution of your app continues normally or until it hits another breakpoint. I used this to figure out what the heck was going on. More on that in the next post. I have a wedding to get to tonight.
In my meatspace copy of Agile Web Development with Rails, page 196 is where I found the directions for what to do. Here's what I did:
I opened the amazon_controller.rb code file down in typo\components\plugins\sidebars. In this file, I was really puzzled by this bit of code:
1 2 |
asin_list = params[:contents].to_a.inject([]) { |acc, item| acc | item.whiteboard[:asins].to_a } |
So, I typed breakpoint() on the line just above this line, saved the file and then I started the WEBBrick server.
Also, following the instructions in the Agile book, I opened a command prompt in the typo directory and ran this command:
ruby script/breakpointer
It's hard to see in the image above, but I had just typed params[:contents] at the irb prompt and all the stuff on the screen is the output of that.
When you're done with one breakpoint, just type 'exit' to leave irb and execution of your app continues normally or until it hits another breakpoint. I used this to figure out what the heck was going on. More on that in the next post. I have a wedding to get to tonight.
Leave a Reply