# Array as Hash value

**URL:** <https://discuss.rubyonrails.org/t/array-as-hash-value/27875>\
**Category:** rubyonrails-talk\
**Created:** [April 11, 2008, 11:14am UTC](https://discuss.rubyonrails.org/t/array-as-hash-value/27875 "2008-04-11T11:14:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Franz\_Strebel](https://avatars.discourse-cdn.com/v4/letter/f/8797f3/32.png) [@Franz\_Strebel](https://discuss.rubyonrails.org/u/Franz_Strebel)\
**Post date:** [April 11, 2008, 11:14am UTC](https://discuss.rubyonrails.org/t/array-as-hash-value/27875/1 "2008-04-11T11:14:59Z")

</div>

something like this.

@hash.each do |k, v| # block variables k - key, v - value

&nbsp;&nbsp;&nbsp;v.each do |a|

&nbsp;&nbsp;&nbsp;end

end

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 11, 2008, 1:23pm UTC](https://discuss.rubyonrails.org/t/array-as-hash-value/27875/2 "2008-04-11T13:23:44Z")

</div>

I dont know, I removed all the bells and whistles from the method, used a static array as input and it simply wont accept that this thing is an array when I try to output it in HTML... Drives me insane...

Could someone please write out the HTML code for accessing a value-array in a Hash?

This is what I tried:

The Hash:

@some\_hash["key"] = @some\_array

In HTML:

\<% for key,values in @some\_hash %\> &nbsp;&nbsp;\<%= key %\> &nbsp;&nbsp;\<% for value in value %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= value %\> &nbsp;&nbsp;\<% end %\> \<% end %\>

But again, "values" is not a array but a string... is it me or is this a rails-specific thing?

---

<div class="post-metadata">

**Author:** ![Franz\_Strebel](https://avatars.discourse-cdn.com/v4/letter/f/8797f3/32.png) [@Franz\_Strebel](https://discuss.rubyonrails.org/u/Franz_Strebel)\
**Post date:** [April 11, 2008, 1:33pm UTC](https://discuss.rubyonrails.org/t/array-as-hash-value/27875/3 "2008-04-11T13:33:43Z")

</div>

\<% @hash.each do |k, v| -%\> &nbsp;&nbsp;\<%= k %\> &nbsp;&nbsp;\<% v.each do |a| -%\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= a %\> &nbsp;&nbsp;\<% end -%\> \<% end -%\>

@hash.each associated with the block will go through each member of your Hash instance, @hash. the block variable k will hold the current key, and the block variable v will hold the value.

as you initialized the value to be an array, you can then call the Array method each to go through each member of your array. associated with a block, the variable a will hold the value of the member.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 11, 2008, 1:41pm UTC](https://discuss.rubyonrails.org/t/array-as-hash-value/27875/4 "2008-04-11T13:41:26Z")

</div>

details, details ... Thx, that worked!
