Im trying to set up a has one relationship in RoR. An agreement has one contact. In the agreement table there is a column called contact_id.
When i try to call an agreenment's contact like so: <%= agreement.contact.name %> (contact table has a column name) I get the error Unknown column 'contacts.agreement_id' Where it should be looking for agreement.contact_id
Any suggestions?
Your
contactstable needs the foreign key migration added, i.e. you need to create a columnagreement_idas integer. Make sure you dorake db:migrateand this should work.Remember, the FK is on the 'belongs_to' table side of the relationship. So, an agreement
has_onecontact and contactbelongs_toagreement.