# Controller access to POST Data in bulk?

**URL:** <https://www.ruby-forum.com/t/controller-access-to-post-data-in-bulk/166742>\
**Category:** Rails\
**Created:** [April 29, 2009, 4:18am UTC](https://www.ruby-forum.com/t/controller-access-to-post-data-in-bulk/166742 "2009-04-29T04:18:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![scafativ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@scafativ](https://www.ruby-forum.com/u/scafativ)\
**Post date:** [April 29, 2009, 4:18am UTC](https://www.ruby-forum.com/t/controller-access-to-post-data-in-bulk/166742/1 "2009-04-29T04:18:16Z")

</div>

Hi,

Ruby N. here, with a question. I’ve written rails web app, and I’d  
like to have the controller log the post data into the info log to keep  
track of how users are using my app. Is there a way to reference all of  
the POST data in bulk, or will I have to call out each field separately?  
The form has a lot of fields, so maintaining the logging feature will be  
a pain if it can’t be done in one wack, by referencing a certain hash or  
something.

Any advice greatly appreciated.

scafativ

---

<div class="post-metadata">

**Author:** ![scafativ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@scafativ](https://www.ruby-forum.com/u/scafativ)\
**Post date:** [April 29, 2009, 5:36am UTC](https://www.ruby-forum.com/t/controller-access-to-post-data-in-bulk/166742/2 "2009-04-29T05:36:32Z")

</div>

Vc Scafati wrote:

> a pain if it can’t be done in one wack, by referencing a certain hash or  
> something.
> 
> Any advice greatly appreciated.

What about the params hash?

---

<div class="post-metadata">

**Author:** ![scafativ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@scafativ](https://www.ruby-forum.com/u/scafativ)\
**Post date:** [April 29, 2009, 5:44am UTC](https://www.ruby-forum.com/t/controller-access-to-post-data-in-bulk/166742/3 "2009-04-29T05:44:03Z")

</div>

7stud – wrote:

> What about the params hash?

And the standard library module yaml can format the output for you:

require ‘yaml’

params = {:name =\> “Ted”, :age =\> 32, :email =\> “removed\_email\_address@domain.invalid”}  
puts YAML.dump(params)

## –output:–

:age: 32  
📧 removed\_email\_address@domain.invalid  
:name: Ted

---

<div class="post-metadata">

**Author:** ![scafativ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@scafativ](https://www.ruby-forum.com/u/scafativ)\
**Post date:** [April 29, 2009, 12:17pm UTC](https://www.ruby-forum.com/t/controller-access-to-post-data-in-bulk/166742/4 "2009-04-29T12:17:35Z")

</div>

ActionController::Request#body

[http://api.rubyonrails.org/classes/ActionController/Request.html#M000701](http://api.rubyonrails.org/classes/ActionController/Request.html#M000701)

dwh

---

<div class="post-metadata">

**Author:** ![scafativ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@scafativ](https://www.ruby-forum.com/u/scafativ)\
**Post date:** [April 29, 2009, 6:25am UTC](https://www.ruby-forum.com/t/controller-access-to-post-data-in-bulk/166742/5 "2009-04-29T06:25:35Z")

</div>

Vc Scafati wrote:

> Hi,
> 
> Ruby N. here, with a question. I’ve written rails web app, and I’d  
> like to have the controller log the post data into the info log to keep  
> track of how users are using my app. Is there a way to reference all of  
> the POST data in bulk, or will I have to call out each field separately?

Do you mean write something like:

puts params[:name]  
puts params[:age]  
puts params[:email]  
…  
…

???

Like most programming languages, ruby has loops, so you could always  
write:

params = {:name =\> “Ted”, :age =\> 32, :email =\> “removed\_email\_address@domain.invalid”}

params.each do |key, val|  
puts “#{key} = #{val}”  
end

–output:–  
name = Ted  
age = 32  
email = removed\_email\_address@domain.invalid

That would allow you to format the data anyway you want.

One advantage of using yaml is that you can later use a method in  
another program to reload the data back into a hash to analyze the data,  
i.e. output all the users by age category or by location. yaml has the  
advantage that it is both human readable and can be reloaded into a  
hash. You can even edit the yaml file by hand.

Similar to yaml is marshall–except marshal is built into ruby and it is  
faster. However, the files marshal generates are not human readable and  
not editable by hand. Marshal is used to store ruby data in a program  
that is stored in hash, array, or object of a class, and then reload the  
object at a later date for use in another program.
