Hello!
I have a list of bands, and each band belongs to one genre:
class Band < ActiveRecord::Base
belongs_to :genre
end
class Genre < ActiveRecord::Base
has_many :bands
end
In the list.rhtml, when I do:
<% for band in @bands %>
<td><%=h band.genre.name%></td>
</tr>
<% end %>
it gives me: _undefined method `name'' for nil:NilClass
_When I do: band.genre.inspect I get: #<Genre:0x86fb610
@attributes={"name"=>"Rock",
"id"=>"1"}>
So the name attr is there. I just can''t access it because seemingly
there''s no accessor. Which is weird, because Rails should have defined
that for me, right?
Echo''ing <%=h band.genre_id%> or even <%=h band.genre.id%>
works.
Any ideas?
Rob