At first I used carrierwave gem rather rudely.
Roughly not at all because of the carrierwave , but because you cannot immediately attach several files to the input . You just need a lot of input and on the server side, process them with a carrierwave , you can even deferred. And yes, in the example you wrote that you need a Picture model, and in it the carrierwave fields are carrierwave . But it was obvious and without using carrierwave . those. if you have a house, then it has a lot of pictures (in Russian, it has a lot of pictures). Here you have a description of the connection, we get:
class House has_many :pictures accepts_nested_attributes_for :pictures end class Picture belongs_to :house #... всё что нужно для carrierwave end
The first option, the easiest thing that comes to mind is to use nested records:
class House has_many :pictures accepts_nested_attributes_for :pictures end
Nested entries are set using the class method ::accepts_nested_attributes_for , which allows you to use nested entries when saving, in your case it is necessary that the attached photos are attached to the house. Please note that using this property you can also delete nested records, and not just add them.
Although in the description there is even an example of code for loading, however, since it is not quite what it is required, you can do something like this: you make one form, for the house, you just include the image attribute fields in it, and they are such a non-weak array that all go when updating to the server:
<%= form_for @house, url: houses_path } do |f| %> # ... <% f.fields_for @house.pictures do |pic| %> <%= pic.file_field :avatar %> #... тут уже код идёт из примера с jQuery-File-Upload <%- end %> <%- end %>
Also, do not forget to properly handle the nested entries in the controller on strong parameters.
You can do as you suggest, that is, a form for the home and many forms for photos, each in form. Only here the restriction is that the form of photos can appear only if the house entry has already been created, and yes, in the form of a photo, there should be a field specifying the house to which the photo belongs. Then you can do without nested records.