The imageable/documentable object is always the object the form builder is based on; since we're already passing the form builder, we don't have to pass the object as well. The only exception are the poll answers. In this case, we're passing a new answer as the object. That's OK; the same hack that we're using to send the data to the answer URL without displaying existing attachments causes the form to keep working the same way.
26 lines
1.1 KiB
Plaintext
26 lines
1.1 KiB
Plaintext
<% image_fields ||= :image %>
|
|
<% imageable = f.object %>
|
|
|
|
<%= f.label image_fields, t("images.form.title") %>
|
|
<p class="help-text"><%= imageables_note(imageable) %></p>
|
|
|
|
<div id="nested-image">
|
|
<%= f.fields_for image_fields do |image_builder| %>
|
|
<%= render Images::FieldsComponent.new(image_builder, imageable: imageable) %>
|
|
<% end %>
|
|
</div>
|
|
|
|
<%= link_to_add_association t("images.form.add_new_image"), f, image_fields,
|
|
force_non_association_create: true,
|
|
partial: "images/image_fields",
|
|
id: "new_image_link",
|
|
class: "button upload-image
|
|
#{"hide" if image_fields == :image && imageable.image.present?}",
|
|
render_options: {
|
|
locals: { imageable: imageable }
|
|
},
|
|
data: {
|
|
association_insertion_node: "#nested-image",
|
|
association_insertion_method: "append"
|
|
} %>
|