0

How can i create a queryset and view (@contacts in my situation) in rhomobile to list ActiveRecord objects alphabetically?

I'm trying to do this implementation;

A -> Contacts starts with A

B -> Contacts starts with B etc.

Final look: http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/lists/lists-divider.html

Thanks

1 Answers1

1

The simplest thing for you would be to sort your queryset and place listdividers (as you would do with jQuery Mobile) in your ERB file whenever the next element starts with a letter that is different from the one of the previous element (this could be achieved through a for-each loop).

I am assuming that you are using the Contacts API from Rhodes (Rhomobile). In that case there actually is an example here where they sort the contacts according to display_name. It should however be noticed that the display_name property only is available on the Android platform. You may therefore want to substitute it with the first_name or last_name properties that are supported on all platforms.

You can find another reference that explains sorting in Ruby here.

corthmann
  • 377
  • 1
  • 2
  • 9