2011-04-10 7 views
10

나는 웹에서 찾을 수있는 모든 예를 통해 사용자 정의 보간을 만드는 데 어려움을 겪어 왔지만, 내가 한 것에 상관없이 성공하지 못했습니다.Rails 3, Paperclip - Custom Interpolations

모델

has_attached_file :photo, 
    :path => ":rails_root/public/images/:img_name-:style.:extension", 
    :styles => { 
    :original => '100x100', 
    :thumb => '30x30' 
} 

초기화/paperclip.rb

Paperclip.interpolates :img_name do |attachment, style| 
    attachment.instance.img_name 
end 

img_name 필드는 이미지 업로드에 형식으로 채워집니다 순간 나는이 있습니다. , C/사용자 /.../ stream20110410-384-stl2lk20110230-213-1fm2bab : /.../ photo_upload/공공/이미지 - : 나는 업로드 할 수 오류는 (C

잘못된 인수 /:img_name-original.jpg)

+0

당신을 감사합니다! 저는 paperclip.rb에서 모델로 옮겼습니다. 지금은 작동합니다 ... – uhandoh

+0

해결책으로 분명하다는 답변으로 추가했습니다. –

답변

10

는 모델에 직접 있다면 작동하는 것 같다 :

class Model < ActiveRecord::Base 

    Paperclip.interpolates :img_name do |attachment, style| 
    attachment.instance.img_name 
    end 

    has_attached_file :photo, 
    :path => ":rails_root/public/images/:img_name-:style.:extension", 
    :styles => { 
     :original => '100x100', 
     :thumb => '30x30' 
    } 

end