2
모델 업데이트 중에 CarrierWave 업 로더 클래스 내의 모델 속성에 액세스하려고합니다.모델 업데이트 중 CarrierWave 모듈의 모델 속성에 액세스
모델을 업데이트 할 때 CarrierWave는 원본 이미지의 크기를 조정하고 크기를 조정하는 프로세스를 실행합니다.
그 과정에서 아래 보이는 것처럼 Photo params 해시의 default_mat 매개 변수에 액세스하려고합니다.
{"utf8"=>"✓", "authenticity_token"=>"+yregNfTKmy78MWFSLQc+z7ufjcs8nkdJSJlBdrTIds=", "photo"=>{"id_num"=>"jh860", "default_frame"=>"1", "show_bw_conversion"=>"true", "rotating_keyword"=>"picture", "image"=>#<ActionDispatch::Http::UploadedFile:0x007ff85768b490 @tempfile=#<Tempfile:/var/folders/jt/wm_zgby1701d31fwp0v9n86h0000gn/T/RackMultipart20150104-69760-sac29l>, @original_filename="1470.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"1470.jpg\"\r\nContent-Type: image/jpeg\r\n">, "image_cache"=>"", "is_active"=>"false", "title"=>"sdfsdfsdfd", "description"=>"<p>sdfsadf</p>", "category_ids"=>["", "1"], "photographer_id"=>"5", "film_type"=>"digital", "year_taken"=>"2015", "format_id"=>"1", "default_mat"=>"1"}, "commit"=>"Add Photo", "action"=>"create", "controller"=>"photos"}
어떻게 해시에서 default_mat 속성/값에 액세스하고 업데이트 중에 CarrierWave 업 로더 클래스에서 사용합니까?
class ProductImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::ImageOptimizer
def frame_photo
manipulate! do |img|
# puts "i am trying to access the #{model.default_mat} value"
mat_frame = MiniMagick::Image.open("http://s3-us-west-2.amazonaws.com/luminoto-modal/fog_black.jpg")
mat_frame.rotate("90") if img.height > img.width
result = mat_frame.composite(img) do |c|
c.compose "Over" # OverCompositeOp
c.gravity "Center" # copy second_image onto first_image from (20, 20)
end
result.resize "525x525>"
result
end
end