2014-12-12 5 views
1

ImageUploader에 추가 프로세스 (auto_orient)를 추가 할 때를 제외하고 예상대로 작동하는 이미지를 업로드했습니다. 다음과 같이 코드는 다음과 같습니다Minimagick : 정의되지 않은 메소드`destroy! ' TrueClass auto_orient

class ImageUploader < CarrierWave::Uploader::Base 
    include CarrierWave::MiniMagick 

    retina! 

    if Rails.env.development? 
    def store_dir 
     "#{Rails.root}/public/uploads/account_#{model.account_id}/product_#{model.product_id}/image_#{model.id}" 
    end 
    elsif Rails.env.staging? || Rails.env.production? 
    def store_dir 
     "uploads/account_#{model.account_id}/product_#{model.product_id}/image_#{model.id}" 
    end 
    end 

    def default_url 
    "/assets/no_image_500px.png" 
    end 


    process :auto_orient 
    process :resize_and_pad => [500, 500] 

    version :thumb_100 do 
    process :resize_and_pad => [100, 100] 
    end 

    version :shopping_cart do 
    process :resize_to_fill => [200, 200] 
    process :retina_quality => 100 
    end 

    version :store_page do 
    process :resize_to_fill => [336, 336] 
    process :retina_quality => 100 
    end 

    version :product_page do 
    process :resize_to_fill => [426, 426] 
    process :retina_quality => 100 
    end 

    def extension_white_list 
    %w(jpg jpeg png tiff) 
    end 

    def auto_orient 
    manipulate! do |img| 
     img = img.auto_orient 
    end 
    end 

end 

Auto_orient 자신의 휴대 전화에서 이미지를 업로드하기 위해 사용자의 목적을 제공, 이미지가 제대로 중심의 자동차이다. 이 현재 코드는 모바일 업로드 이미지에서 작동하지만 데스크톱에서 웹 앱의 이미지를 업로드하려고하면 "undefined method`destroy! '메시지가 나타납니다. true : TrueClass "를 선택하십시오.

나는 minimagick에 대해 documentation을보고 auto_orient를 auto_orient로 변경한다고 생각했습니다! 그러나 minimagick에는 auto_orient라는 메서드가 없다고 들었습니다. 왜이 방법으로 파괴가 불려지나요?

+0

auto_orient 메서드가 true 또는 object를 반환하는지 확인하십시오. 주로 방법! true 또는 false를 반환합니다. 조작 대신 조작 방법을 바꾸어보십시오!. – Saravanan

+0

분명히 carrierwave 모듈에 auto_orient (!가없는) 메서드가 없습니다. 설명서를 보면 img가 반환 된 것처럼 보입니다. – Tommyixi

+0

@Tommyixi 귀하의 질문에, 당신은 그것을 반대 방법으로 씁니다. 어느 것이 옳은가? –

답변

3

마치 조작 된 것처럼 보입니다. auto_orient (boolean (true)로 끝남)의 반환시 destroy 메소드를 호출합니다. 따라서 불리언에 delete를 호출 할 수 없다는 오류가 발생합니다. 이 문제를 해결하려면, 나는 블록에 이미지를 전달하고 즉시 나중에 이미지를 반환하기 위해 루비 "탭"방법을 추가 :

def auto_orient 
    manipulate! do |img| 
     img.tap(&:auto_orient) 
    end 
    end 
+0

방금 ​​나에게 큰 두통을 저장했다 - 고마워! – erwald

0

은 아마도 대답 질문에 너무 늦게하지만 난에 대한 또 다른 대답을 파괴 해결! 반환해야하는 문제 및 내부 조작 img 블록

def auto_orient 
    manipulate! do |img| 
     img = img.auto_orient 
     img 
    end 
    end