Given a Rails backend and a Vue frontend, how can I POST to the nested ImageAttachment
class? A Photo
can have one ImageAttachment
. I have these strong parameters set up, it feels like the issue is there but I can't find anything.
def photo_params
params.require(:photo).permit(
image_attachment: %i[data crop_x crop_y crop_width crop_height revert]
)
end
This is the Vue function that attaches the child (ImageAttachment
) info to the parent Photo
.
uploading: function (file, xhr, formData) {
formData.append('photo[image_attachment][data]', file)
}
But how it stands gives this error:
ActiveRecord::AssociationTypeMismatch - ImageAttachment(#70277552586900) expected, got {"data"=>#, @original_filename="30594959_1160903097380019_7860735199103942656_o.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image_attachment][data]\"; filename=\"30594959_1160903097380019_7860735199103942656_o.jpg\"\r\nContent-Type: image/jpeg\r\n">} which is an instance of ActiveSupport::HashWithIndifferentAccess(#70277506611620):