Hey @DimaSamodurov!
Have you ever tried the attachment on an embedded model?
I have a Gallery model and a Photo model. The Gallery embeds_many :photos (Photo is embedded_in :gallery) and I have defined attachment :image, type: :image field on the Photo model.
class Gallery
include Mongoid::Document
field :name, type: String
embeds_many :photos
accepts_nested_attributes_for :photos, allow_destroy: true
end
class Photo
include Mongoid::Document
attachment :image, type: :image
embedded_in :gallery
end
In the view I'm using nested forms via Cocoon, so that I can add one or more Photos to the Gallery.
Now when I fill in the whole form (Gallery + 1 Photo) and save it, everything gets saved except the image attachment to the Photo model. This is what is in the 'galleries` collection in the DB after save:
{
"_id" : ObjectId("55f03cae618ead3f6800000a"),
"name" : "first gallery",
"photos" : [
{
"_id" : ObjectId("55f04787618ead534b000002")
}
]
}
As you can see the embedded Photo document has been created, but is missing the image_id property.
I checked what comes from the form to the controller - all the data is there (including the refile JSON with uploaded image data).
Any ideas how could this be solved?
Hey @DimaSamodurov!
Have you ever tried the
attachmenton an embedded model?I have a Gallery model and a Photo model. The Gallery
embeds_many :photos(Photo isembedded_in :gallery) and I have definedattachment :image, type: :imagefield on the Photo model.In the view I'm using nested forms via Cocoon, so that I can add one or more Photos to the Gallery.
Now when I fill in the whole form (Gallery + 1 Photo) and save it, everything gets saved except the image attachment to the Photo model. This is what is in the 'galleries` collection in the DB after save:
As you can see the embedded Photo document has been created, but is missing the
image_idproperty.I checked what comes from the form to the controller - all the data is there (including the refile JSON with uploaded image data).
Any ideas how could this be solved?