I have some records:
Type Name
2 USA
2 USA
3 Canada
4 Mexico
1 Canada
2 Mexico
3 USA
I just want to show the list of unique types: 1,2,3,4 (no double, triple records).
I was trying to do something like that in my view:
<% @Orders.group(:type).each do |order| %>
... showing in the table
<% end %>
But I got following error:
undefined method `group’ for #
Do I need to add some method in the controller/model?
Why – if .each method works ok in the view, group doesn’t?
It’s a little unclear what exactly you are trying to return/display, but I think you might want to look at
#group_by(http://api.rubyonrails.org/classes/Enumerable.html#method-i-group_by).Alternatively, look at some of the aggregate methods on this page: http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-calculate