Sorting collection lists


#1

I’m using collection.select lists and I would love to sort them by one
or two of the columns as the lists are getting long enough to make a
difference.

<%= options = [[‘Select a Facility’, ‘’]] + @facility.collect {
|fac| [fac.name, fac.id] }
select ‘placement’, ‘facility_id’, options %>

how do I get this to order by facility.name ?

Craig


#2

On Tue, 2006-02-28 at 17:11 +0000, Alex Y. wrote:

 select 'placement', 'facility_id', options %>

thanks - at least I now recognize why I couldn’t intuitively figure this
out.

Craig


#3

Craig W. wrote:

<%= options = [[‘Select a Facility’, ‘’]] + @facility.collect {
|fac| [fac.name, fac.id] }
select ‘placement’, ‘facility_id’, options %>

how do I get this to order by facility.name ?
<%= options = [[‘Select a Facility’, ‘’]] +
@facility.sort{|a,b|
a.name <=> b.name }.collect{|fac|
[fac.name, fac.id] }
select ‘placement’, ‘facility_id’, options %>