我创建了表单,但是在单击时,选择图像选项不会附加添加多个图像。 请给我一个解决方案
我的财产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
这就是我获取页面的方式,单击“添加图像”时,选择图像的多个选项未显示。 请给我一个解决方案
答案 0 :(得分:3)
我不清楚你的代码中是否呈现了实际的文件输入。但是对于多个文件选择,您需要这样的代码:
<%= f.file_field :image, multiple: true, require: true %>
答案 1 :(得分:0)
您可以使用
MyControl.Style = DirectCast(FindResource("labelStyle2"), Style)
而不是<%= file_field_tag "images[]", type: :file, multiple: true %>
如果您要上传多张图片,那么将会在from参数中创建一个图像数组,名称为images []