group_by in rails by 2 or more attributes April 19, 2023 by Tarik Why not do: @bunch.group_by{|e| [e.commentable_id, e.commentable_type]}