如何在视图中显示此哈希?

时间:2015-03-04 14:28:58

标签: ruby-on-rails ruby-on-rails-4

如何在视图中显示此哈希?

class Credit < ActiveRecord::Base
  serialize :credit_data
end

我得到了哈希,但我无法在视图中显示它。

=> [#<Credit:0x00000005d49900
  id: 18,
  credit_data:
   {3000=>[{1=>492}, {2=>984}, {3=>1536}, {4=>2136}, {5=>2760}],
    4000=>[{1=>656}, {2=>1328}, {3=>2048}, {4=>2816}, {5=>3620}],
    5000=>[{1=>820}, {2=>1648}, {3=>2560}, {4=>3544}, {5=>4540}],
    ........
  created_at: Wed, 04 Mar 2015 14:22:59 UTC +00:00,
  updated_at: Wed, 04 Mar 2015 14:22:59 UTC +00:00>]

1 个答案:

答案 0 :(得分:0)

我不确定,但你可以尝试这样的事情

<table>
    <tr>
        <% credit_data.each do |k,v| %>
            <th><%= k %></th>
            <% v.each do |v1| %>
                <td><%= v1.values %></td> 
            <% end %>
        <% end %>
    </tr>
</table>