Ruby on rails 4 如何使用carrierwave上载现有项目的多个文件

Ruby on rails 4 如何使用carrierwave上载现有项目的多个文件,ruby-on-rails-4,carrierwave,multiple-file-upload,Ruby On Rails 4,Carrierwave,Multiple File Upload,这是my_form.html.erb中的附件代码 <div class="control-group"> <%= f.label :attachment , :class => 'control-label' %> <div class="controls"> <%= f.file_field :attachment, :class => 'file_field', multiple: 'true' %

这是my_form.html.erb中的附件代码

<div class="control-group">
      <%= f.label :attachment , :class => 'control-label' %>
      <div class="controls">
        <%= f.file_field :attachment, :class => 'file_field', multiple: 'true' %>
      </div>
    </div>

'控件标签'%>
“文件\字段”,多个:“真”%>
这是我的型号发票。\u details.rb

class InvoiceDetail < ActiveRecord::Base
    mount_uploader :attachment, AttachmentUploader
  #validates :invoice_number, :supplier_name, :attachment, presence: true # Make sure the owner's name is present.    
  #validates_uniqueness_of :invoice_number
 #validates :invoice_number, length: { maximum: 7 }
 #validates :supplier_name, length: { maximum: 20 }
 #validates :description_of_goods, length: { maximum: 50 }
 #validates :quatity, numericality: true
 #validates :price_per_unit, numericality: true
 #validates :total_amount, numericality: true
end
classinvoicedetail
这里是另一个模型invoice_file.rb

class InvoiceFile < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader # Tells rails to use this uploader for this model.
  validates :name, presence: true # Make sure the owner's name is present.  
end
class InvoiceFile
您可以使用文件字段输入在表单中添加动态嵌套字段,但这是一个糟糕的解决方案,因为这样,当有人试图一次上载20个文件时,您可能会遇到超时问题

我认为最简单、最快的解决方案是使用“jquery fileupload rails”gem。请检查演示应用程序的源代码,并根据您的应用程序进行调整

下面是一个很好的例子: