|
||||||||||||||||||||||
|
||||||||||||||||||||||
September 22, 2006 I sometimes help people out with Rails and Ruby coding issues in #rubyonrails on EFNet. One of the biggest issue most of them have is a lack of knowledge of what tools they have available for debugging when using Rails. script/breakpointer is an awesome tool when it comes to Rails debugging. Here's how to use it: Start a new terminal or command prompt or whtever sort of shell you use. Run .ruby script/breakpointer You should see a prompt something like this: > script/breakpointer No connection to breakpoint service at druby://localhost:42531 (DRb::DRbConnError) Tries to connect will be made every 2 seconds... The breakpointer uses DRB, which you can read more about here . If for some reason you get errors, try this alternate version of the same command: ruby script/breakpointer -c druby://localhost:12345 At this point you are ready to insert a breakpoint into your code. Find the place in your code where you think the problem might exist. I usually start in the view and work back towards the controller, and eventually to the model if required. For example if I am having trouble trying to pull some users out of my database, I might add a breakpoint in the view like this: <% breakpoint %> <% @users.each do |u| -%> ... <% end -%> When execution hits the breakpoint, everything will stop. You may reach this point simply by reloading the page that is having the problem. Now, as your browser sits patiently waiting for something to happen, something else has happened in your running breakpointer instance, something that looks like this perhaps: Executing break point at /Users/destiney/rails/game/trunk/public/../ config/../app/views/player/_signup.rhtml:2 in `_run_rhtml_player__signup' irb(#<#<Class:0x2745bac>:0x2745b84>):001:0> Now you can easily interogate your variables to see if they contain what you think they should. Try typing @users for example. When done, hit Ctrl + D to step through the breakpoints until you regain access to the execution. You can leave the breakpointer running the whole time you're coding. Until you actually enter a breakpoint command in your code it will sit and wait for you. Good Luck!
|
|
|||||||||||||||||||||
|
||||||||||||||||||||||