我正在尝试使用 Dragonfly 一次上传多个文件并存储它们。我能够通过向我的模型添加一个document_uid
和来成功上传和存储单个文件,但现在我想创建为每个对象上传多个文件的能力,所以我需要在他们自己的表中使用 FK 到表.document_name
case
case
document_uid
document_name
case
我目前收到错误:Document(#70285786863740) expected, got ActionDispatch::Http::UploadedFile(#70285766684260)
应用程序/模型/case.rb
class Case < ActiveRecord::Base
has_many :documents
attr_accessible :documents
end
class Document < ActiveRecord::Base
belongs_to :case
dragonfly_accessor :document # defines a reader/writer for an uploaded document
attr_accessible :document_uid, :document_name
end
看法
<%= form_for(@case) do |f| %>
...
<%= f.file_field :documents, :multiple => true %>
...
<% end %>
到目前为止,我的控制器中只有默认的创建方法
# POST /cases
# POST /cases.json
def create
@case = Case.new(params[:case])
respond_to do |format|
if @case.save
format.html { redirect_to @case, notice: 'Case was successfully created.' }
format.json { render json: @case, status: :created, location: @case }
else
format.html { render action: "new" }
format.json { render json: @case.errors, status: :unprocessable_entity }
end
end
end
参数:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"KAsjoqrQT5HTNKsiH6bu3+MRKB0FKDLdP2Q/Gm9ZYdA=", "case"=>{"documents"=>[#<ActionDispatch::Http::UploadedFile:0x007fd95ebe97d8 @original_filename="Screen Shot 2014-01-25 at 8.59.17 PM.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"case[documents][]\"; filename=\"Screen Shot 2014-01-25 at 8.59.17 PM.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<Tempfile:/var/folders/5w/tkmvdtbn2xn98hjy655s67tw0000gn/T/RackMultipart20140727-43998-1go1ez0>>, #<ActionDispatch::Http::UploadedFile:0x007fd95ebe9760 @original_filename="Screen Shot 2014-03-02 at 8.38.22 AM.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"case[documents][]\"; filename=\"Screen Shot 2014-03-02 at 8.38.22 AM.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<Tempfile:/var/folders/5w/tkmvdtbn2xn98hjy655s67tw0000gn/T/RackMultipart20140727-43998-1kefqe0>>]}, "button"=>""}
是什么导致了这个错误,我该如何规避它?