1

i created form, but on click ,choose image option is not appending to add multiple images. Please give me a solution for this

my property form.html.erb

<%= simple_nested_form_for ([:generic_users, @property]) do |f| %>
<%= f.input :image, required: true %>
    <p><%= image_tag @property.image_url(:thumbnail) if @property.image? %></p>
    <%= f.hidden_field :image_cache %>
    <%= f.simple_fields_for :property_images do |i| %>
      <%= i.input :image %>
      <p><%= image_tag i.object.image_url(:thumbnail) if i.object.image? %></p>
      <%= i.hidden_field :image_cache %>
      <%= i.link_to_remove 'Remove',method: :delete, class: 'btn btn-danger'%>
    <% end %>
   </div>
   </div>
   <hr>
   <%= f.link_to_add 'Add Image', :property_images, class: 'btn btn-primary', data: {target: '.additional-images'} %>
  <hr>
<% end %>

this is my propertyImage model

class PropertyImage < ActiveRecord::Base
  belongs_to :property
  validates_presence_of :image
  mount_uploader :image, ImageUploader
end

my property.rb

class Property < ActiveRecord::Base
has_many :property_images, dependent: :destroy
accepts_nested_attributes_for :property_images, allow_destroy: true
end

This is how i am getting page , on clicking Add Image , multiple option for choose image is not appearing. Please give me a solution

enter image description here

2 Answers 2

3

It's not clear to me from your code where the actual file input is being rendered. However for multiple file selections you would want code something like this:

<%= f.file_field :image, multiple: true,  require: true %>
Sign up to request clarification or add additional context in comments.

Comments

1

You can use

<%= file_field_tag "images[]", type: :file, multiple: true %> 

instead of <%= f.file_field :image, multiple: true, require: true %>

if you will upload multiple images then there will be an array of images will be create in the from parameter with name images[]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.