2014-10-14 2 views
0

많은 Paperclip 자르기 자습서를 살펴본 결과 내가 잘못하고있는 것이 무엇인지 모르겠지만 제대로 작동하지 않습니다. 튜토리얼은 모두 구식이므로 궁금한 점이 있으시면 ...레일 용 종이 클립 사용자 정의 자르기 4

내가 사용한 최신 튜토리얼은 here입니다.하지만 오류는 설명이 아닙니다. 이 내 모바일 앱에 단지 서버 측 그대로

ActionView::MissingTemplate (Missing template profiles/failed to update, application/failed to update with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby]

내가 어떤 견해를 가지고 있지 않습니다 나는 Heroku가에 Rollback과 뒤에

An error was received while processing: #<Paperclip::Error: There was an error processing the thumbnail for 1dc9f9eee29a7fd2f3f68e9c264b6d5420141014-13-v9mj79

를 얻을. 나는 후자의 오류가 롤백 후에 나타나기 때문에 관련이 없다고 추측하지만 나는 실수 할 수있다. 내 컨트롤러 내 모바일 앱에서 전송

데이터의 형식은 :

Parameters: {"profile"=>{"picture1_url"=>"http://a_url_here.com/sdfsdf.jpg", "crop_x"=>384, "crop_y"=>0, "crop_w"=>201, "crop_h"=>182}, "id"=>"123"}

그리고 마지막으로, 내 코드는 아래에 나열되어 있습니다. 내가 자르기를 방해하는 것은 무엇을 잘못하고 있습니까? 또는 프로세서를 사용하지 않기 위해 모델의 has_attached_file에 명령을 전달할 수도 있습니까? 내 모델에서 이런 식으로 뭔가 :

# I tried this already and it didn't work but is there some other way to do this? 
# Also keep in mind I will need to pass variables crop_y,crop_x, etc. 
has_attached_file :picture1, styles: { 
    crop: "-crop '#{crop_w}x#{crop_h}+#{crop_x}+#{crop_y}" 
} 

내 실제 코드는 아래와 같습니다 :

내 모델 profile.rb :

has_attached_file :picture1, styles: { 
    crop: {processors: [:cropper]} 
}, url: "pictures/:facebook_id/:style/1:dotextension", 
path: ":rails_root/public/:url" 

attr_accessor :crop_x, :crop_y, :crop_w, :crop_h 

내 컨트롤러 profiles_controller.rb :

def profile_params 
    # I have other things I permit but only showing the crop values 
    params.require(:profile).permit(:crop_w,:crop_x,:crop_h,:crop_y) 
end 

내 프로세서 cropper.rb :

module Paperclip 
    class Cropper < Thumbnail 
    def initialize(file, options = {}, attachment = nil) 
     super 
     @current_geometry.width = target.crop_w 
     @current_geometry.height = target.crop_h 
    end 
    def target 
     @attachment.instance 
    end 
    def transformation_command 
     crop_command = ["-crop","#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}"] 
     crop_command + super 
    end 
    end 
end 

답변

0

문제프로세서가

내가 target.crop_w이 프로세서에서 인식 얻을하는 방법을 알아낼 수없는 등 target.crop_w을 인식하지 않은 것이 었습니다.

결국 나는 람다 인스턴스를 통해 스타일에 변수를 전달했습니다. 예를 들어 인스턴스에 crop_w를 설정하면

has_attached_file :picture1, styles: lambda {|a| { 
    crop: {processors: [:cropper], 
      crop_w:a.instance.crop_w, 
      crop_x:a.instance.crop_x, 
      crop_y:a.instance.crop_y, 
      crop_h:a.instance.crop_h} 
    } 
    } 

a.instance.crop_w에만 존재합니다. 나를 위해 그래서, 내 컨트롤러에서 나는

@profile = Profile.find_by_id(params[:id]) 

# 
@profile.picture1_from_url(params[:profile][:picture1_url],params[:profile][:crop_w ...) 

같은 것을했고 picture1_from_url 내가 URL의 클립 이미지를 다운로드하는 방법이었다. 이 방법과 같이 모델에 있습니다 self.crop_w = crop_w를 설정하여

def picture1_from_url(url,crop_w,crop_x,crop_h,crop_y) 
    self.crop_w = crop_w 
    #repeat above line with crop_h crop_y crop_x 
    self.picture1 = URI.parse(url) 
end 

가 나는 그것이 lambdastyles에 액세스 할 수있었습니다 이유 인스턴스에 해당 변수를 부착.

마지막으로이 옵션을 전달하면 옵션 해시를 통해 프로세서에서 액세스 할 수 있습니다. 내 프로세서에서 :

def options 
    @options 
end 

def transformation_command 
    crop_command = ["-crop","#{options[:crop_w]}x#{options[:crop_h]}+#{options[:crop_x]}+#{options[:crop_y]}"] 
    crop_command + super 
end 

그리고 내가 어떻게 작동시켜야하는지.

관련 문제