ActiveModel::MissingAttributeError: can’t write unknown attribute `ad_id’ with FactoryGirl

When you say:

has_one :image

Rails expects you to define an ad_id field at the images table. Given the way your associations are organised, I assume you have an image_id and a logo_id a the ads table so instead of:

class Ad < ActiveRecord::Base
  belongs_to :page

  has_one :image
  has_one :logo
end

You probably mean:

class Ad < ActiveRecord::Base
  belongs_to :page
  belongs_to :image
  belongs_to :logo
end

If that’s not the case then you need to add ad_id columns to both Image and Logo.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)