我使用Carrierwave file upload上传和下载文件。 我的模特:
class InvoiceDetail < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
validates :invoice_number, :supplier_name, :attachment, presence: true
validates_uniqueness_of :invoice_number
end
附接/ uploader.rb:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def filename
“#{model.invoice_number}。#{file.extension}”if original_filename.present? 端
invoice_detail / _form.html.erb:
<%= form_for(@invoice_detail , html: {class: 'form-horizontal', role: 'form' }) do |f| %>
<div class="field">
<%= f.label :invoice_number, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :invoice_number, :class => 'text_field' %>
</div>
</div>
<div class="field">
<%= f.label :supplier_name, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :supplier_name, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :attachment , :class => 'control-label' %>
<div class="controls">
<%= f.file_field :attachment, :class => 'file_field' %>
</div>
</div>
<div class="form-actions">
<%= f.submit "Create Invoice Details", :class => 'btn btn-primary' %>
<%= f.submit "cancel", :class => 'btn btn-danger', method: :delete, data: { confirm: 'Are you sure you want to cancel' } %>
</div>
<% end %>
目前的代码在单个文件上传时运行良好。 现在我的要求是存储多个文件(多个文件上传),当我点击下载时,所有同一个ID下的多个文件都必须压缩和下载。