Hi All,
I have a one to many relationship between images and gifts (one image
can be assigned to multiple gifts):
class ProductImage < ActiveRecord::Base
has_many :gifts
…
class Gift < ActiveRecord::Base
belongs_to :product_image
…
I’m trying to associate an image with a gift, and for the life of me
ActiveRecord will not associate them. Here is some test code and the
associated output:
gift.product_image = ProductImage.find_or_create()
p “PRODUCT IMAGE IS: #{gift.product_image}”
gift.product_image.save
p “PRODUCT IMAGE IS: #{gift.product_image}”
gift.save
p “PRODUCT IMAGE IS: #{gift.product_image}”
gift.reload
p “PRODUCT IMAGE IS: #{gift.product_image}”
gift.save
p “PRODUCT IMAGE IS: #{gift.product_image}”
and the output is:
“PRODUCT IMAGE IS: #ProductImage:0xb73e6a40”
“PRODUCT IMAGE IS: #ProductImage:0xb73e6a40”
"PRODUCT IMAGE IS: "
"PRODUCT IMAGE IS: "
"PRODUCT IMAGE IS: "
AS soon as I go and save the gift, the image gets wiped out - the
association never makes it into the database. Any ideas how this could
be?
Thanks!
Tom