मैं पेपर क्लिप का उपयोग कर एकाधिक फ़ाइलें अपलोड समस्याओं कर रहा हूँ के साथ अपलोड कर रहा है एक से अधिक फ़ाइलों,पेपरक्लिप
अपने मॉडलरूप में इस तरह
slider has_many imgarrays
imgarrays has_many imageobjects
imageobjects have_attachment(as for paperclip)
हैं मुझे कोई एक ही छवि प्राप्त करने और पर पेपर क्लिप का उपयोग कर यह बचत समस्या है मेरी अन्य मॉडल, लेकिन मुझे यकीन नहीं है कि एकाधिक फ़ाइल अपलोड के दौरान imgarrays
param द्वारा लौटाई गई सरणी को कैसे संभालना है।
यहाँ मेरी रेल सर्वर लॉग है: हम हासिल कर सकते हैं:
Started POST "/slider" for 127.0.0.1 at 2012-07-23 10:14:17 +0800
Processing by SliderController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"7HcHtSlOsU/bnxb9emhAsSl/GFBraIE6NxwijHl3REM=", "slider"=>{"question"=>"", "answer"=>"", "score"=>"", "industry_name"=>"",
"imgarrays"=>[#<ActionDispatch::Http::UploadedFile:0x007fb471e99f30 @original_filename="Icon.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"slider[imgarrays][]\"; filename=\"Icon.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<File:/var/folders/2s/n9wb5x4534nfs1cbrlph32v00000gp/T/RackMultipart20120723-53499-1lyi4yf>>, #<ActionDispatch::Http::UploadedFile:0x007fb471e99dc8 @original_filename="[email protected]", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"slider[imgarrays][]\"; filename=\"[email protected]\"\r\nContent-Type: image/png\r\n", @tempfile=#<File:/var/folders/2s/n9wb5x4534nfs1cbrlph32v00000gp/T/RackMultipart20120723-53499-10lala2>>, #<ActionDispatch::Http::UploadedFile:0x007fb471e99d50 @original_filename="greenButton.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"slider[imgarrays][]\"; filename=\"greenButton.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<File:/var/folders/2s/n9wb5x4534nfs1cbrlph32v00000gp/T/RackMultipart20120723-53499-or2rdk>>]}, "commit"=>"Create!"}
Completed 500 Internal Server Error in 18ms
ActiveRecord::AssociationTypeMismatch (Imgarray(#70206507050500) expected, got ActionDispatch::Http::UploadedFile(#70206487229960)):
app/controllers/slider_controller.rb:12:in `new'
app/controllers/slider_controller.rb:12:in `create'
Rendered /Users/Kinnovate/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
Rendered /Users/Kinnovate/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.4ms)
Rendered /Users/Kinnovate/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (6.5ms)
स्लाइडर के लिए new.html.erb
<div>
<%= form_for @slider ,:url=>"/slider" , :html => { :multipart => true } do |f| %>
<%= f.label :question , "question"%>
<%= f.text_field :question %> </br>
<%= f.label :answer , "answer array (comma seperated)"%>
<%= f.text_field :answer %> </br>
<%= f.label :score , "score"%>
<%= f.text_field :score %> </br>
<%= f.label :industry_name , "industry"%>
<%= f.text_field :industry_name %> </br>
<%= f.label :attachedimg , "image"%>
<%= f.file_field :imgarrays, :multiple =>:true %> </br>
<%= f.submit "Create", class: "btn btn-large btn-primary" %>
<% end %>
</div>
<%= link_to 'Cancel', slider_index_path %>
क्या आप लौटा सरणी के माध्यम से फिर से चलाने के लिए थोड़ी देर लूप का उपयोग नहीं कर सकते? – pat34515
ओह आदमी, इतना आसान समाधान, धन्यवाद! क्या आप एक उत्तर पोस्ट कर सकते हैं ताकि मैं स्वीकार कर सकूं? – henghonglee
[पेपरक्लिप, एकाधिक अनुलग्नक और सत्यापन] के संभावित डुप्लिकेट (http://stackoverflow.com/questions/4800985/paperclip-multiple-attachments-and- validation) –