I am having problems display an attribute in a belongs_to relationship. Lease belongs_to Unit. Unit has a column "number" in the db. When I try to display this attribute on the lease show page, it gives me an error of undefined method `number' for nil:NilClass. I feel like I'm doing something stupid and over looking it.
@lease = Lease.find(params[:id])
<%= @lease.unit.number %>
Your model may have unit_id attribute, but how about
units that does not have that record with
id = 1 have You checked?
Quick (dirty) fix:
<%= @lease.unit.number unless @lease.unit.nil? %>