1

i am using Carrierwave file upload for uploading and downloading the files. my model:

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}" if original_filename.present? end

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 %>

The present code is working fine with single file upload. Now my requirement is to store multiple files (Multiple file upload) and when I click on download all the multiple files under same id has to be zipped and downloaded.

sachin god
  • 685
  • 2
  • 12
  • 29

1 Answers1

0

please follow the link multiple upload for multiple uploads. And in order to download your files as a zip, one of the finest method is to use rubyzip gem.

Community
  • 1
  • 1
raj_on_rails
  • 144
  • 1
  • 11