How to group_by this array of hashs (Enumerable) [Ruby, Rails]

Viewed 459

I have an array (@items) of hashs with this structure:

@items:

{'item' => item, 'stickers' => stickers}
...

And the item is an ActiveRecord with the attr I want to group_by: csgo_type.

My code:

<% @items.group_by { |d| d['item'][:csgo_type] }.each do |a| %>
    <%= render partial: 'item', locals: {a: a} %>
<% end %>

But this doesnt group at all.

I'm looking for a result like this:

[ { :csgo_type => #ActiveRecord(csgo_type 1), :items => [array of some @items of this type] }, {...} ...]

1 Answers
Related