Select Collection with Conditions - May Help You

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| [c.name, c.id] } %>

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

Cheers,
David

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs