Reputation: 3136
i am trying to run a activerecord statement like this
@items=History.count(:group => "DATE(timelogin)")
on my view i am, trying to show my records in html table like this
<table class="table table-striped table-bordered table-condensed">
<% @item.each do |key,val| %>
<tr>
<td> <% key %></td>
<td> <% val %></td>
</tr>
<% end %>
</table>
i tried something else and while searching over i came up with following link What is the best way to convert an array to a hash in Ruby and i replaced my view code as it is shown in the link.
but it does nothing. i later added =
like this
<%= @item.each do |key,val| %>
it showed whole result in once and rendered empty table.
the result that is rendered on webpage and in rails console is like:
{"2014-01-08"=>1, "2013-12-31"=>2, "2013-12-30"=>2, "2013-12-26"=>5, "2013-12-24"=>1,
"2013-12-23"=>1, "2013-12-20"=>2, "2013-12-18"=>2, "2013-12-17"=>2, "2013-12-04"=>1,
"2013-12-03"=>5, "2013-12-02"=>1, "2013-11-28"=>7, "2013-11-20"=>1, "2013-11-19"=>1,
"2013-11-18"=>1, "2013-11-12"=>1, "2013-11-06"=>1, "2013-10-29"=>2, "2013-10-25"=>1,
"2013-10-23"=>1, "2013-10-15"=>1, "2013-10-14"=>3, "2013-10-10"=>2}
Please let me know what wrong i have done.
Upvotes: 0
Views: 419
Reputation: 3895
Try this
<table class="table table-striped table-bordered table-condensed">
<% @item.each do |key,val| %>
<tr>
<td> <%= key %></td>
<td> <%= val %></td>
</tr>
<% end %>
</table>
Upvotes: 1
Reputation: 14943
Missing =
. Use it to output. Also, you are using @item
in the view, but assigning the values to @items
in the code. There is a missing s
.
<% @items.each do |key,val| %>
<tr>
<td> <%= key %></td>
<td> <%= val %></td>
</tr>
<% end %>
Upvotes: 4