diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb
index 348c2641e..192f06d04 100644
--- a/app/models/direct_upload.rb
+++ b/app/models/direct_upload.rb
@@ -19,9 +19,10 @@ class DirectUpload
if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?)
@resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id)
- if true #@resource.class.reflections[@resource_relation].macro == :has_one
- #@relation = @resource.send("build_#{resource_relation}", relation_attributtes)
+ if @resource.respond_to?(:images)
@relation = @resource.images.send("build", relation_attributtes)
+ elsif @resource.class.reflections[@resource_relation].macro == :has_one
+ @relation = @resource.send("build_#{resource_relation}", relation_attributtes)
else
@relation = @resource.send(@resource_relation).build(relation_attributtes)
end
diff --git a/app/views/admin/poll/questions/answers/images/index.html.erb b/app/views/admin/poll/questions/answers/images/index.html.erb
index 09d055783..79333b660 100644
--- a/app/views/admin/poll/questions/answers/images/index.html.erb
+++ b/app/views/admin/poll/questions/answers/images/index.html.erb
@@ -1,9 +1,9 @@
<%= back_link_to admin_question_path(@answer.question) %>
+
+ <%= link_to "Add image", new_admin_answer_image_path(@answer) %>
+
+
<% @answer.images.each do |image| %>
<%= render_image(image, :large, true) if image.present? %>
<% end %>
-
-
- <%= link_to "Add image", new_admin_answer_image_path(@answer) %>
-
\ No newline at end of file
diff --git a/app/views/admin/poll/questions/answers/images/new.html.erb b/app/views/admin/poll/questions/answers/images/new.html.erb
index 14156a79d..80126bef7 100644
--- a/app/views/admin/poll/questions/answers/images/new.html.erb
+++ b/app/views/admin/poll/questions/answers/images/new.html.erb
@@ -1,66 +1,10 @@
<%= form_for(Poll::Question::Answer.new,
url: admin_answer_images_path(@answer),
method: :post) do |f| %>
+
- <%# render 'images/nested_image', imageable: @answer, f: f %>
-
- <%= f.label :images, t("images.form.title") %>
+ <%= render 'images/nested_image', imageable: @answer, f: f, image_fields: :images %>
- <%# imageables_note(imageable) %>
-
-
- <%= f.fields_for :images do |image_builder| %>
- <%# render 'images/image_fields', f: image_builder, imageable: imageable %>
-
- <%= f.hidden_field :id %>
- <%= f.hidden_field :user_id, value: current_user.id %>
- <%= f.hidden_field :cached_attachment %>
-
-
- <%= f.text_field :title, placeholder: t("images.form.title_placeholder") %>
-
-
- <%= render_image(f.object, :thumb, false) if f.object.attachment.exists? %>
-
-
-
- <%= render_image_attachment(f, @answer, f.object) %>
-
-
- <%= render_destroy_image_link(f, f.object) %>
-
-
-
-
-
- <%= image_attachment_file_name(f.object) %>
-
-
-
-
-
-
-
- <% end %>
-
-
- <%= link_to_add_association t('images.form.add_new_image'), f, :images,
- force_non_association_create: true,
- partial: "images/image_fields",
- id: "new_image_link",
- class: "button hollow",
- render_options: {
- locals: { imageable: @answer }
- },
- data: {
- association_insertion_node: "#nested-image",
- association_insertion_method: "append"
- } %>
-
-
-
<%= f.submit "Save image" %>
<% end %>
\ No newline at end of file
diff --git a/app/views/images/_nested_image.html.erb b/app/views/images/_nested_image.html.erb
index 2f65b8760..ff9e3d242 100644
--- a/app/views/images/_nested_image.html.erb
+++ b/app/views/images/_nested_image.html.erb
@@ -1,17 +1,20 @@
-<%= f.label :image, t("images.form.title") %>
+<%= image_fields ||= :image %>
+
+<%= f.label image_fields, t("images.form.title") %>
<%= imageables_note(imageable) %>
- <%= f.fields_for :image do |image_builder| %>
+ <%= f.fields_for image_fields do |image_builder| %>
<%= render 'images/image_fields', f: image_builder, imageable: imageable %>
<% end %>
-<%= link_to_add_association t('images.form.add_new_image'), f, :image,
+<%= 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 hollow #{"hide" if imageable.image.present?}",
+ class: "button hollow
+ #{"hide" if image_fields == :image && imageable.image.present?}",
render_options: {
locals: { imageable: imageable }
},