如何实现多文件上传以及如何使用carrierwave rails下载与zip具有相同id的文件?
How to implement multiple file upload and how to download the files with same id as a zip using carrierwave rails?
我正在使用 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
attachment/uploader.rb:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def filename
"#{model.invoice_number}.#{file.extension}" 如果 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 下的所有多个文件。
请按照link multiple upload进行多次上传。
为了将文件下载为 zip,最好的方法之一是使用 rubyzip gem.
我正在使用 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
attachment/uploader.rb:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def filename
"#{model.invoice_number}.#{file.extension}" 如果 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 下的所有多个文件。
请按照link multiple upload进行多次上传。 为了将文件下载为 zip,最好的方法之一是使用 rubyzip gem.