something what should really be easy and I can’t get it to work…
I have a Relation which has_many Contacts and Contact belongs_to Relation. Now I want to show the relation name in the contact index view. In the contacts controller I have this:
@contacts = Contact.paginate :page => params[:page],
:include => :relations,
:per_page => 10,
:order => "last_name"
Now I expect in the index view to be able to use this:
<%= contact.relation.name %>
But it returns a undefined method "name" for nil:NilClass error? Thanks for your help!
My guess is that you have at least one
Contactobject that doesn’t have an associatedRelationobject, which is why it’s trying to call.nameon a nil value.You can try doing something like this temporarily to see if you have some Contacts without Relations:
and see what gets displayed.