2013-02-15 1 views
4

일부 업 데이트 기능을 수행 한 후 픽업 업 로더를 마운트해야합니다.레일 웨이브 컨디셔닝 장착 상태에서

하지만 모델에서 일반적인 설치 업 로더로 호출하는 경우 :

mount_uploader :content, ContentUploader 

carrierwave 첫 번째 다운로드 콘텐츠를 다음 레일 모델의 검증을 시작합니다.

특히 큰 파일을 전혀로드하지 않으려 고합니다. http 헤더 Content-lengthContent-type을 확인한 다음 업 로더를 마운트하고 확인하십시오. 그런

아마 뭔가 :

if condition 
    mount_uploader :content, ContentUploader 
end 

내가 어떻게 할 수 있습니까?

P. Rails 버전 3.2.12

답변

1

대용량 파일을로드하지 않으려면이 방법을 사용할 수 없습니다! 즉, 조건부 마운트가 content=을 무시할 수 있습니다.

CarrierWave v1.1.0에는 여전히 조건부 탑재가 없습니다. 하지만 mount_uploader 먼저 includes a module 클래스에 다음 overrides 원래 content=content=defined 포함 된 모듈에서 호출 할 수 있습니다. 당신이 mount_uploader 불렀다 후 그래서 해결 방법은 접근을 재정의하는 단지입니다 :

class YourModel < ActiveRecord::Base 
    mount_uploader :content, ContentUploader 

    def content=(arg) 
     if condition 
      super 
     else 
      # original behavior 
      write_attribute(:content, arg) 
     end 
    end 

    def content 
     # some logic here 
    end 
end 
관련 문제