I have a table that is displaying a list of 5 items. Next to each item I
want to display the number of times that the item pops up in an
individual list. Example:
Item1 (4)
Item2 (2)
Item3 (1)
Item4 (7)
Item5 (3)
Here is my code as is:
Index.rhtml.erb
<%= table.item1 + ‘’ + @statcount %>
<%= table.item2 + ‘’ + @statcount %>
<%= table.item3 + ‘’ + @statcount %>
<%= table.item4 + ‘’ + @statcount %>
<%= table.item5 + ‘’ + @statcount %>
And the code used for counting each item in the controller (here is
where I’m having trouble)
item_ids = 1…5
statcount_query = item_ids.map{|id| "item#{id} = BLANK “}.join(” OR
")
@statcount = table.count(:all, :conditions => statcount_query).to_s
Where I have written BLANK is where I can’t find the right code to
insert. I need to define/pass <%= table.item1 %> into this section, but
I’m quite lost on how to do it exactly. I’ve tried several methods, but
they keep returning nothing or the total amount of items in the table.
Any help would be greatly appreciated!