我是一个有用的助手,会翻译文本。
为什么我不能使用"self.id"来获取收据ID? 为什么
处理器代码
我正在尝试理解如何将模型值发送到Paperclip自定义处理器中,但就是无法弄清楚为什么这么困难,或者可能的解决方案是什么,因为我已经尝试解决这个问题好几天了...下面是从我的模型和处理器中提取出来的代码。
从我的模型:
...
has_attached_file :receipt_file,
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "/:style/:id/:filename",
:s3_protocol => "https",
:styles => { :text => { style: :original, receipt_id: self.id }},
processors: [:LearnProcessor]
...
为什么我不能使用"self.id"来获取收据ID? 为什么
"/:style/:id/:filename"
会被翻译成/original/1/abc.pdf
,如果我放置receipt_id: :id
,那么从options[:receipt_id]
中得到的只是:id
而不是1
?
我需要一些内插吗?处理器代码
module Paperclip
class LearnProcessor < Processor
attr_accessor :receipt_id,:style
def initialize(file, options = {}, attachment = nil)
@file = file
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
@style = options[:style]
@receipt_id = options[:receipt_id]
puts "Options #{options.inspect}"
end
...