How can i create a queryset and view (@contacts in my situation) in Rails 3 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
You have to do something like this:
@users = User.all.group_by{|u| u.name[0]}
In the view:
<% @users.keys.sort.each do |starting_letter| %>
<%= starting_letter %>
<% @users[starting_letter].each do |user| %>
<%= user.name %>
<% end %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With