2014-12-23 5 views
0

이벤트 has_many : images, : : imageable 및 Image belongs_to : imageable, polymorphic : true와 같은 이미지 모델과 같은 이벤트 모델이 있습니다. 나는 carrierwave를 사용하고 있으며 하나의 이미지를 이벤트에 쉽게 업로드 할 수 있습니다. 그러나 필요한 시나리오는 여러 이미지를 각 이벤트에 업로드하는 것입니다. 또한 여러 이미지를 업로드 할 때 매개 변수의 이미지를 얻습니다. 난 그냥 대신에 단일 AJAX를 보낼 것입니다 uploadify 같은 어떤 jQuery 플러그인을 사용할 수 있습니다, 그것은 한 번에 여러 개의 이미지를 업로드 시간이 소요 될 수 이러한 매개 변수를 사용하는 방법을 알고 이미지반송파 레일에 여러 이미지 업로드

Event.rb 
class Event < ActiveRecord::Base 
    has_many :images, as: :imageable 
    mount_uploader :image, EventImageUploader 



Image.rb 

class Image < ActiveRecord::Base 
    belongs_to :imageable, polymorphic: true 



Parameters in console on multiple input 



    Parameters: {"utf8"=>"✓", "authenticity_token"=>"h75pCP+/S9rt16aFMXAagtaJq5msxWBUt9wfYzSinB8=", "event"=>{"title"=>"sfdf", "starts_at"=>"2014-12-10 14:47", "ends_at"=>"2014-12-17 14:47", "url"=>"https://softwaysolutions.atlassian.net/wiki/display/RADIO/2014/10/31/Radio+App+Initial+DB+Design", "description"=>"fssdfdfsf", 
"image"=>[#<ActionDispatch::Http::UploadedFile:0x0000000a5e93e0 @tempfile=#<Tempfile:/tmp/RackMultipart20141223-12927-1izxog6>, @original_filename="a1.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"event[image][]\"; filename=\"a1.jpg\"\r\nContent-Type: image/jpeg\r\n">, 
#<ActionDispatch::Http::UploadedFile:0x0000000a5e93b8 @tempfile=#<Tempfile:/tmp/RackMultipart20141223-12927-vs0l0e>, @original_filename="a7.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"event[image][]\"; filename=\"a7.jpg\"\r\nContent-Type: image/jpeg\r\n">, 
#<ActionDispatch::Http::UploadedFile:0x0000000a5e9390 @tempfile=#<Tempfile:/tmp/RackMultipart20141223-12927-1q3vr93>, @original_filename="a8.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"event[image][]\"; filename=\"a8.jpg\"\r\nContent-Type: image/jpeg\r\n">, 
#<ActionDispatch::Http::UploadedFile:0x0000000a5e9368 @tempfile=#<Tempfile:/tmp/RackMultipart20141223-12927-1ccn4dk>, @original_filename="angular_logo.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"event[image][]\"; filename=\"angular_logo.png\"\r\nContent-Type: image/png\r\n">, 
#<ActionDispatch::Http::UploadedFile:0x0000000a5e9340 @tempfile=#<Tempfile:/tmp/RackMultipart20141223-12927-ur48if>, @original_filename="email_2.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"event[image][]\"; filename=\"email_2.jpg\"\r\nContent-Type: image/jpeg\r\n">]}, "commit"=>"Create Event"} 

답변

0

를 저장하지 않습니다 업로드 할 때마다 요청하십시오. 그렇게하면 어떤 이미지 업로드가 실패했는지 또는 성공했는지 여부를 모니터링 할 수 있습니다.