# How to sort records?

**URL:** <https://www.ruby-forum.com/t/how-to-sort-records/50827>\
**Category:** Rails\
**Created:** [December 21, 2005, 4:52pm UTC](https://www.ruby-forum.com/t/how-to-sort-records/50827 "2005-12-21T16:52:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brutyn\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5f8ce5/32.png) [@Brutyn\_N](https://www.ruby-forum.com/u/Brutyn_N)\
**Post date:** [December 21, 2005, 4:52pm UTC](https://www.ruby-forum.com/t/how-to-sort-records/50827/1 "2005-12-21T16:52:58Z")

</div>

hey,  
Âµ  
i have these records in my database, in a many-to-many relationship

clients\_users  
1;66  
2;66  
3;66  
5;66  
6;66  
7;66  
8;66  
14;66  
15;66  
16;66  
17;66  
18;66  
19;66  
20;66  
21;66  
22;66

clients  
1;VME Complex Foster  
2;VME Res. Canada  
3;Twodecode  
5;Index  
6;Verleye bvba  
7;Venus bvba  
8;All Building Services nv  
14;Vitro-Service sa  
15;Vitro-Clean  
16;Vecom nv  
17;Ultra lean bvba  
18;Solar Cleaning Services nv  
19;Service Net nv  
20;Schoonmaakbedrijf VIP-Clean  
21;Romarco nv  
22;Pele

i want to sort those clients.

in my controller i have this

@clients\_access = @user.clients

in my rhtml  
\<% for client in @clients\_access %\>  
\<%= client.name %\>  
\<% end %\>

with output this

VME Complex Foster VME Res. Canada Twodecode Index Verleye bvba Venus bvba ...........

can anyone help me sort them?

Thanks  
Nick

---

<div class="post-metadata">

**Author:** ![Brutyn\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5f8ce5/32.png) [@Brutyn\_N](https://www.ruby-forum.com/u/Brutyn_N)\
**Post date:** [December 21, 2005, 5:05pm UTC](https://www.ruby-forum.com/t/how-to-sort-records/50827/2 "2005-12-21T17:05:03Z")

</div>

class User \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :clients, :order =\> “name ASC”  
end

should do the trick
