2012-07-26 2 views
0

내 웹 사이트의 사용자가 최대 3 개의 이미지를 업로드 할 수 있도록 허용합니다. 그래서 내 양식에 나는이 요소가 : 만 3 이미지 이하의 유효성을 검사 일부 자바 스크립트를 선택하고있다레일/클립에 이미지 배열 처리

<label>Additional Images*<span class="note">(Maximum: 3, 200 pixels wide)</span></label> 
<%= f.file_field :images, { :multiple => "", :accept => "image/*" } %> 
<div id="images"></div> 

을, 또한 이미지의 축소판을 생성하고 # 이미지를 div에있는 자식으로 추가합니다. 사용자가 양식을 제출하면, 다음 :

has_attached_file :image1, 
    ... 

has_attached_file :image2, 
    ... 

has_attached_file :image3, 
    ... 

내가 :

내 모델에서
[ #<ActionDispatch::Http::UploadedFile:0x00000007269588 
    @original_filename="test_banner.jpeg", 
    @content_type="image/jpeg", 
    @headers="Content-Disposition: form-data; name=\"custom_form[images][]\"; filename=\"test_banner.jpeg\"\r\nContent-Type: image/jpeg\r\n", 
    @tempfile=#<File:/tmp/RackMultipart20120726-7134-3hqdve>>, 
    #<ActionDispatch::Http::UploadedFile:0x00000007269510 
    @original_filename="test_portrait.jpeg", 
    @content_type="image/jpeg", 
    @headers="Content-Disposition: form-data; name=\"custom_form[images][]\"; filename=\"test_portrait.jpeg\"\r\nContent-Type: image/jpeg\r\n", 
    @tempfile=#<File:/tmp/RackMultipart20120726-7134-18fcs0m>>, 
    #<ActionDispatch::Http::UploadedFile:0x00000007269498 
    @original_filename="test_signiture.jpeg", 
    @content_type="image/jpeg", 
    @headers="Content-Disposition: form-data; name=\"custom_form[images][]\"; filename=\"test_signiture.jpeg\"\r\nContent-Type: image/jpeg\r\n", 
    @tempfile=#<File:/tmp/RackMultipart20120726-7134-1q5fy2f>> ] 

, 내가 3 개 속성이 있습니다 이미지 매개 변수는 다음과 같습니다 이미지 정보의 배열로 채워집니다 폼과 함께 전송되는 이미지 매개 변수의 정보가 분할되어 모델의 각 이미지 속성으로 전송되도록하고, 사용자가 하나 또는 두 개의 이미지 만 업로드하면 다른 속성은 무효화됩니다. 제가 종이 클립으로이 작업을 할 수있는 방법이 있습니까?

답변

0

3 x file_fields 만 만들 것을 강력히 제안합니다. 그러면 모든 것이 정리되고 유효성 검사만으로도 효과가 있습니다. 나는 그것이 매끈 매끈하지 않다는 것을 안다. 그러나 1-3 이미지를 위해. .. 정말로 큰 거래.

+0

나는 그것이 더 쉬울 것이라는 것을 안다. 그러나 사용자와 앱에 매우 불편할 것이다. –