views:

1571

answers:

5

there is a scaffold created Story... and in the create action, there is

@story = Story.new(params[:story])

i was curious as to what is in params... so i want to dump out params... but there is no view associated with the create action... is there a way to dump out its content? is there a way to dump out the POST variables in of my code too? (to see what's going on in the lower level)

+4  A: 

The easiest thing to do is just dump params out to the log:

Rails.logger.info("PARAMS: #{params.inspect}")

If you're in development mode, just look in your development.log and that line will be there.

The params scope is a combination of URL/FORM (GET/POST) fields, and it will be printed out in the log as part of the normal output processing, so you might not need your own dumping of it - any development or production log contains the params dump at the top of the log line, e.g.

Processing Clients::ClientsController#show (for x.x.x. at 2009-05-24 00:34:26) [GET]
  Parameters: {"id"=>"303", "user_id"=>"2"}
Cody Caughlan
Is this regardless of the log_level?
@willem obst - no, you're right, this will only print out when the log level is info or lower. You can use Rails.logger.debug to print it out in either development or production.
Cody Caughlan
+1  A: 

If you're on a Mac, Spike is a great little app the analyses log files and will let you inspect params for requests, amongst other things.

dylanfm
A: 

Using Fiddler on Windows, it is shown

the HTTP line #1 is:

POST /stories HTTP/1.1

this is the POST content:

authenticity_token=62iw%2BrsxlCFsbnxsS7FXKRn6CcvJfjottrsBPlM5lZo%3D&story%5Bname%5D=Google+Main+Site&story%5Blink%5D=www.google.com&commit=Create

listed in a table:

authenticity_token  62iw+rsxlCFsbnxsS7FXKRn6CcvJfjottrsBPlM5lZo=
story[name]         Google Main Site
story[link]         www.google.com
commit              Create

and the server log is:

Parameters: {"commit"=>"Create", "story"=>{"name"=>"Google Main Site", "link"=>"www.google.com"}, "authenticity_token"=>"62iw+rsxlCFsbnxsS7FXKRn6CcvJfjottrsBPlM5lZo="}

動靜能量
+1  A: 

You don't need to anything except look in your logs (they live in /log). Unless you're fiddling with something, the logging of parameters is turned on by default in all logs.

Processing PostsController#create (for 127.0.0.1 at 2009-05-24 13:03:24) [POST]
  Parameters: {"commit"=>"Create", "authenticity_token"=>"2G6BKOs8xNAaXiToVf4r1ko8QZzP9QAomi2PHVQC5Oc=", "story"=>{"something"=>"asdfafd"}}

Parameters lists all parameters, and the hash following "story" is the equivalent of params[:story] (everything comes to the server as strings, and Rails turns it into a HashWithIndifferentAccess so that you can access it with a symbol).

Ian Terrell
A: 

If you're on a *NIX system (including OS X) open a new terminal window/tab and type the following command:

tail -f log/development.log

You'll get a constant stream of requests coming in -- including params -- and the resulting DB actions. Invaluable for development/debugging, IMO.