Forum: Ruby on Rails how to sort records??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Brutyn N. (Guest)
on 2005-12-21 17:52
(Received via mailing list)
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 %>
	<option value="<%= client.id %>"><%= client.name %></option>
<% end %>

with output this
<option value="1">VME Complex Foster</option>
<option value="2">VME Res. Canada</option>
<option value="3">Twodecode</option>
<option value="5">Index</option>
<option value="6">Verleye bvba</option>
<ption value="7">Venus bvba</option>
...........

can anyone help me sort them?

Thanks
Nick
Chris H. (Guest)
on 2005-12-21 18:05
(Received via mailing list)
class User < ActiveRecord::Base
  has_and_belongs_to_many :clients, :order => "name ASC"
end

should do the trick
This topic is locked and can not be replied to.