something like this.
@hash.each do |k, v| # block variables k - key, v - value
v.each do |a|
end
end
something like this.
@hash.each do |k, v| # block variables k - key, v - value
v.each do |a|
end
end
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 %> <%= key %> <% for value in value %> <%= value %> <% end %> <% end %>
But again, "values" is not a array but a string... is it me or is this a rails-specific thing?
<% @hash.each do |k, v| -%> <%= k %> <% v.each do |a| -%> <%= a %> <% 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.
details, details ... Thx, that worked!