Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in Ruby on Rails 2.3.2, how to print out params during a create action?

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)

like image 827
nonopolarity Avatar asked May 24 '09 05:05

nonopolarity


2 Answers

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"}
like image 90
Cody Caughlan Avatar answered Sep 25 '22 00:09

Cody Caughlan


Now I know Rails more, you can also simply use a

p params

in your code and look at the console's output (the log shown on the console)

like image 41
nonopolarity Avatar answered Sep 25 '22 00:09

nonopolarity