开发者

Remove square brackets and inverted commas from view, rails 3

开发者 https://www.devze.com 2023-03-08 07:45 出处:网络
I have an each statement in a view: <tr><% @quantity.each do |hash| %> <td><%= hash.map { |key, value| \"Channel: #{key} Quantity: #{value} units\" } %>

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
0

精彩评论

暂无评论...
验证码 换一张
取 消