How to sort records?


#1

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


#2

class User < ActiveRecord::Base
has_and_belongs_to_many :clients, :order => “name ASC”
end

should do the trick