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.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-28 18: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
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-02-28 18:18
(Received via mailing list)
Craig White 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 %>
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-28 18:24
(Received via mailing list)
On Tue, 2006-02-28 at 17:11 +0000, Alex Young 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.