SOには同様の質問/回答が多数ありますが、私の問題を解決するものはないようです。
私の目標は、Paperclip を使用して、画像の「動的透かし」(別の画像にユーザー アバター オーバーレイ) を生成することです。私が抱えている問題は、モデルの「user_id」属性を取得して、動的プロセッサを使用してアバター ファイル/URL を取得できないことです。「watermark.rb」プロセッサを使用していることに注意してください (インターネットの他の場所にあります)。静的透かしを正常に生成できますが、attachment.instance は nil です。参照してください:
class NicerImage < ActiveRecord::Base
attr_accessible :content, :image, :user_id
belongs_to :user
has_attached_file :image,
:styles => lambda { |attachment| {
:large => {
:processors => [:watermark],
:geometry => "800>",
:watermark_path => User.find(attachment.instance.user_id).avatar.url(:medium),
:position => 'SouthEast'
}
}
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/aws.yml",
:bucket => Rails.configuration.s3[:general_bucket],
:convert_options => { :all => "-auto-orient" }
end
私が得ているエラーは、nil:NilClass の未定義メソッド `user_id=' です (attachment.instance が nil であるため)
ありがとう!