Forum: Ruby on Rails Select Collection with Conditions - May Help You...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
David H. (Guest)
on 2006-04-12 10:05
Hey All:

Thought I'd pass this along...let me know if you have a better, more
elegant way.

Still new to Rails, but was fiddling around with the Select Helper
trying to return an option collection that was filtered (in other words,
I didn't want every item from the collection, just the ones that met a
certain criteria).

I used find_all_by_ to do it and it looks like this in my view:

<% select 'deal', 'supplier', Client.find_all_by_is_supplier(true,
:order => 'name').collect { |c| [,] } %>

Note the sort order as well. Hope this helps someone...

This topic is locked and can not be replied to.