I have been creating a view in the form, which has images, but I can not find the way to show the previous images that I am selecting to leave or remove them before uploading them to the bd, either to create or to edit. I enclose my form and I await your help. Thanks.
<div class="row">
<%= simple_form_for [:admin, @history], validate: true, html: {multiple: true} do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<div class="col-lg-12 col-md-12 col-xs-12">
<div class="col-lg-12 col-md-12 col-xs-12">
<div class="form-inputs">
<%= f.input :title, label: "Título", required: true, autofocus: true %>
</div>
</div>
</div>
<div class="col-lg-12 col-md-12 col-xs-12">
<div class="col-lg-12 col-md-12 col-xs-12">
<div class="form-inputs">
<%= f.input :description, label: 'Description', as: :text, :input_html => {:style => 'width: 100%', :rows => 5, class: 'response-project'} %>
</div>
</div>
</div>
<div class="col-lg-12 col-md-12 col-xs-12">
<div class="control-group">
<div class="col-lg-12 col-md-12 col-xs-12">
<%= f.fields_for :images_attributes do |images_fields| %>
Image: <%= images_fields.file_field :image, :multiple => true,name: "images_attributes[image][]" %>
<% end %>
<%# f.attachment_field :images_files, multiple: true, presigned: true, direct: true %>
</div>
</div>
</div>
<div class="col-lg-12 col-md-12 col-xs-12">
<hr>
<center>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")), admin_histories_path(:history_status => "publicada"), :class => 'btn btn-default' %>
<%= f.submit 'Aceptar', :class => 'btn btn-primary' %>
</center>
<p>
</div>
<% end %>
</div>
My models are:
image.rb
class Image < ApplicationRecord
belongs_to :imageable, polymorphic: true, optional: true
mount_uploader :picture, PictureUploader
end
hystory.rb
class History < ApplicationRecord
belongs_to :user
has_many :images, as: :imageable, dependent: :destroy
accepts_nested_attributes_for :images, allow_destroy: true
validates :title, presence: true
validates :description, presence: true
end
Bearing in mind that I am using polymorphism and that there are several images that I am uploading and not only one.