Something new for Rails stuff, in a small place.
One of the models depends on the other in the has_many / belongs_to association.
In principle, when creating Mail in my application, the user can also attach Images. Ideally, these are two separate models. When the user selects a photo, some JavaScript uploads it to Cloudinary, and the returned data (ID, width, height, etc.) is built by JSON and set in a hidden field.
# The HTML = f.hidden_field :images, :multiple => true, :class => "image-data"
And of course, relationships exist in my Post model
has_many :images, :dependent => :destroy accepts_nested_attributes_for :images
and my image model
belongs_to :post
Where am I lost what to do with serialized image data in the method of creating a Post controller? Just by analyzing JSON and saving it, it does not create image models with data when saving (and does not feel good):
params[:post][:images] = JSON.parse(params[:post][:images])
All this essentially ends with roughly the following parameters:
{"post": {"title": "", "content": "", ..., "images": [{ "public_id": "", "bytes": 12345, "format": "jpg"}, { ..another image ... }]}}
This whole process seems a bit confusing - what should I do now, and is there a better way to do what I'm trying to do first? (There are also strong parameters needed for nested attributes like ...?)
EDIT:
At this moment, I got this error:
Image(#91891690) expected, got ActionController::Parameters(#83350730)
coming from this line ...
@post = current_user.reviews.new(post_params)
It doesn't seem like it is creating images from nested attributes, but it was expected. (The same thing happens when: autosave is there or not).