Re: undefined method & has_one

Jeff Cohen
Wed, 01 Nov 2006 22:47:34 -0000

Ryan wrote:
> Ilan,
>
> No luck there.
>
> It seems that the method "bio" is not being recognized in the
Employee
> Class. Period.
>
>
> To test this, I tried @employees.bio.each do |bio|, and it also gives me
> the same message.
>

You misunderstood Ilan.  bio is an instance method of an Employee
instance, not a method of the @employees *collection*.

So you call .bio on each *employee* object individually, not on the
collection as a whole.  To collect up all the bios for each employee,
you can do something like this in your controller:

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

Now @bios is an array of all of the bio objects for the given category.

Presumably in your view you could now iterate over this collection:

<% @bios.each do |bio|
<%= bio.name %>
%>

Make sense?