Re: undefined method & has_one

Jeff Cohen
Wed, 01 Nov 2006 23:28:33 -0000

Ryan wrote:
> Jeff,
>
> Thanks!  That does make sense, and I''ve been able to proceed a
bit.
> Although, in your example above: @bios = @category.employees.collect {
> |employee| employee.bio }  returns Employee records that do not have
> bios, evidenced by some bio records returning nil.
>

You can filter those out by calling .compact on the collectoin:

@bios = @category.employees.collect { |employee| employee.bio }.compact

I don''t think there''s a more direct way to do what you want,
except
maybe to write your own SQL to do the query (which would be faster in
this case).

Feels like there should be a better way though, right?  If I can think
of a better way I''ll let you know.

Jeff