Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1
How to Read Code | 55

Under FastCGI, the worker processes would not be able to interact with the
console.
$ script/server
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not
work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.


  1. Interact with your application as needed to trigger the debugger. The request
    will hang in the browser, and the server console will drop into the debugger con-
    sole and show the line of code it is paused on:
    app/controllers/signup_controller.rb:5 @query = params[:q]
    (rdb:1)


Since we called the debugger from within the controller, our debugger console has
full access to the controller’s lexical environment (the binding from whichdebugger
was called). Thus, we can examine request parameters and step through code just as
in the previous example. We have the full set of ruby-debug commands available:


app/controllers/signup_controller.rb:5 @query = params[:q]
(rdb:1) pp params
{"commit"=>"Check for Service",
"action"=>"check_for_service",
"q"=>"Nevada, MO",
"controller"=>"signup"}
(rdb:1) n
app/controllers/signup_controller.rb:6 if @query
(rdb:1)
app/controllers/signup_controller.rb:7 @result = Geocoder.geocode @query
(rdb:1)
app/controllers/signup_controller.rb:8 if @result
(rdb:1) pp @result
{:point=>
#<GeoRuby::SimpleFeatures::Point:0x32c2d08
@m=0.0,
@srid=4326,
@with_m=false,
@with_z=false,
@x=-94.359055,
@y=37.842806,
@z=0.0>,
:address=>"Nevada, MO, USA"}
Free download pdf