Displaying an array of AR objects alphabetically

Hi *, I have an array of AR objects that I’ve been able to sort
alphabetically that I need to split by letter, for example { :a =>
[apple],
:b => [banana] } and so on, based on an attribute that I use for
sorting.
The end result should be something like

  • A
    • Apple
  • B
    • Banana
    • and so on.
      I have no idea how to do this…
      The array is already sorted alphabetically using the DB.

      Can someone help me?
      ngw

On 22 August 2012 17:26, ngw [email protected] wrote:

  • B
    • Banana
    • and so on.
      I have no idea how to do this…
      The array is already sorted alphabetically using the DB.

    Is it that you do not know how to write the ruby code to iterate the
    records? If your objects are in @records then you can use
    @records.each.

    Colin

    Hi!

    Take a look at the method group_by: