私は次のようなハッシュを持っています:
@json = [{"id"=> 1, "username" => "Example"}, {"id"=> 2, "username" => "Example 2"}]
私はこのようなことをしたい:
<ul>
<% @json.each do |user| %>
<li><%= user.username %></li>
<% end %>
</ul>
そして、2 つのユーザー名を含むリストを出力します。
IRBでこれを試してみました:
json2 = [{"id"=> 1, "username" => "Example"}, {"id"=> 2, "username" => "Example 2"}]
irb(main):076:0> json2.each do |user|
irb(main):077:1* user["id"]
irb(main):078:1> end
=> [{"id"=>1, "username"=>"Example"}, {"id"=>2, "username"=>"Example 2"}]
irb(main):079:0>