다음 클립 클립 설정이 있습니다. 무슨 일이 일어나는가 나는 proc을 사용하여 다양한 스타일의 크기를 설정하고있다. 그러나 proc은 새로운 호출과 수퍼 호출 중에 호출됩니다. 나는 디버거를 통해 걸 으면서 : photo 매개 변수를 먼저 처리하므로 첨부 파일을 초기화하고 실제 객체 (사진)가 전달 된 매개 변수 (특히 photo.gallery_id)에 의해 초기화되지 않은 스타일 proc를 호출합니다. 그래서 제대로 스타일을 설정하지 않습니다. 심지어 재 처리를 시도하고 도움이되지 않았다. 난 여전히이에 며칠과 행운을 보냈어요. 어떤 도움에 감사드립니다! 것과동적 문서 클립 초기화되기 전에 호출 된 Proc 스타일
class Photo < ActiveRecord::Base
has_and_belongs_to_many :staffs
has_attached_file :photo,
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/assets/:id/:class/:style/:image_name.:extension",
:url => "/assets/:id/:class/:style/:image_name.:extension",
:styles => Proc.new { |clip| clip.instance.attachment_styles}
def attachment_styles
if self.gallery.nil?
{ :original => {
:processors => [:watermark],
:geometry =>"600x800!",
:watermark_path => ':rails_root/public/images/watermark.png',
:position => 'SouthEast'},
:thumbnail => {
:processors => [:watermark],
:geometry => "200x300!",
:watermark_path => ':rails_root/public/images/watermark.png',
:position => 'SouthEast'}
}
elsif self.photo.styles.empty?
gallery_type = GalleryType.find_by_id(self.gallery_id)
{ :original => {
:processors => [:watermark],
:geometry =>"#{gallery_type.width_max}x#{gallery_type.height_max}!",
:watermark_path => ':rails_root/public/images/watermark.png',
:position => 'SouthEast'},
:thumbnail => {
:processors => [:watermark],
:geometry => "#{gallery_type.width_min}x#{gallery_type.height_min}!",
:watermark_path => ':rails_root/public/images/watermark.png',
:position => 'SouthEast'}
}
else
self.photo.styles
end
end
def reprocess_att
self.photo.reprocess!
end
def initialize(galleryid, params = {})
begin
param.merge!({"gallery_id" => galleryid.to_s})
super(params)
rescue => e
puts e.message()
end
end