I have two model objects, Document and Images. Here are the relevant
declarations:
class Document < ActiveRecord::Base
has_many :images
class Image < ActiveRecord::Base
belongs_to :document
The database tables exist and foreign keys are set up correctly.
In my controller, on an initial request, calling @document.images
(nothing in it yet) is fine.
However, after I attempt to manipulate the images collection by doing:
@document.images << images //in this case, images is an empty
Array object
and then trying to address @document.images, I get the following error:
undefined method `images’ for #Document:0x365d6b0
By looking at the session information, I can see that “images” is being
treated as an instance variable of the document object, and not as an
attribute - it is not listed in the attributes hash inside the document
object in the session.
Has anyone ever seen this behavior before? It’s like my document
“forgets” that it “has” images and then I can no longer count on the
ActiveRecord base methods to manipulate the images collection.
Thanks,
Wes