0

ここに私の _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>

ここに私のモデルinvoice_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

ここに別のモデル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
4

1 に答える 1

0

ファイルフィールド入力を使用して動的にネストされたフィールドをフォームに追加できますが、それは悪い解決策です. 一度に20ファイル。

最も簡単で最速の解決策は、「jquery-fileupload-rails」gem を使用することだと思います。デモ アプリのソース コードを確認し、アプリケーションに合わせて調整してください。

これが良い例です:
https://github.com/n0ne/Rails-Carrierwave-jQuery-File-Upload

于 2015-03-21T15:27:15.627 に答える