Forum: Ruby on Rails sorting collection lists

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.
Craig W. (Guest)
on 2006-02-28 19:12
(Received via mailing list)
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
Alex Y. (Guest)
on 2006-02-28 19:18
(Received via mailing list)
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 %>
Craig W. (Guest)
on 2006-02-28 19:24
(Received via mailing list)
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
This topic is locked and can not be replied to.