# Post variables

**URL:** <https://www.ruby-forum.com/t/post-variables/148653>\
**Category:** Rails\
**Created:** [September 15, 2008, 11:09pm UTC](https://www.ruby-forum.com/t/post-variables/148653 "2008-09-15T23:09:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 15, 2008, 11:09pm UTC](https://www.ruby-forum.com/t/post-variables/148653/1 "2008-09-15T23:09:07Z")

</div>

I need to display all the posted variables and their values. I am not  
sure how I would go about doing this. Is there a way to loop through all  
the posted variables regardless of how many are passed so I could  
display them on a webpage? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 16, 2008, 12:04am UTC](https://www.ruby-forum.com/t/post-variables/148653/2 "2008-09-16T00:04:36Z")

</div>

On 15 Sep 2008, at 22:09, Shandy N. wrote:

> I need to display all the posted variables and their values. I am not  
> sure how I would go about doing this. Is there a way to loop through  
> all  
> the posted variables regardless of how many are passed so I could  
> display them on a webpage? Thanks,

They’re all in the params hash, which is just a regular ruby hash.

Fred

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 16, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/post-variables/148653/3 "2008-09-16T16:15:15Z")

</div>

On Tue, Sep 16, 2008 at 3:52 PM, Shandy N. \<  
removed\_email\_address@domain.invalid\> wrote:

> regardless of what they are named before hand? Thanks,  
> Since it’s a Hash, you can do each to go through the keys and values  
> eg

params.each { |k, v| puts “the key #{k} has value #{v}” }

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 16, 2008, 3:52pm UTC](https://www.ruby-forum.com/t/post-variables/148653/4 "2008-09-16T15:52:40Z")

</div>

Frederick C. wrote:

> They’re all in the params hash, which is just a regular ruby hash.
> 
> Fred

I understand that part, but what if I don’t neccissarily know the names  
of the hash values? I know that there is always params[:action] and  
params[:controller], but what if I had params[:id] when I hit one method  
but when I hit another method I have a params[:admin\_id], or something  
completely different. I guess when I am trying to ask (and the easy way  
would probably be just to try and see if it works) is, can I say  
params.each and then loop through all the values that are passed in  
regardless of what they are named before hand? Thanks,

-S
