I have an each statement in a view:
<tr><% @quantity.each do |hash| %>
<td><%= hash.map { |key, value| "Channel: #{key} Quantity: #{value} units" } %>
</td><% end %></tr>
which is rendering on the webpage with square brackets and inverted commas, thus:
["Channel: 1 Quantity: 4675 units"]
["Channel: 2 Quantity: 2864 units"]
The arra开发者_开发百科y of hashes that it's looping round is this:
[{2=>2864}, {1=>4675}]
How do I stop the [" from showing up on the page?
Thanks!
map
maps a hash into an array. The output is what it should be. Instead of using map
, try:
@quantity.each do |hash|
hash.inspect
end
Should help.
Edit in response to your comment:
@quantity.each do |hash|
hash.each do |key, value|
"Key: #{key} Value: #{value}"
end
end
精彩评论