Paperclip.interpolates随机不返回值

时间:2010-12-01 06:54:43

标签: ruby-on-rails paperclip

我的模型中有以下回形针设置:

  #Paperclip for photo
  has_attached_file :photo,
                    :styles => {
                      :large => '1024x758>',
                      :medium => "200x150#",
                      :small => "50x50>"
                    },
                    :default_style => :original,
                    :default_url => '/images/:attachment/default_:style.png',
                    :path => ":instance_id/:attachment/:id/:version/:style/:basename.:extension",
                    :storage => :s3,
                    :s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
                    :s3_protocol => 'https'

for instance_id我有以下内容:

Paperclip.interpolates :instance_id do |attachment, style|

  def instance_id(attachment, style)
    attachment.instance.instance_id
  end

end

当我第一次启动服务器时,发生了什么事情,我注意到了我的图像404。我原以为是Amazon S3,但后来我查看了URL,发现有时paperclip.interpolates没有返回instance_id。

知道为什么吗?你有过这样的经历吗?

由于

1 个答案:

答案 0 :(得分:2)

如果我理解你想要达到的目标,那么以下内容应该有效:

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

FYI:你的插值过程定义了一种方法,但实际上没有做某事......

希望这有帮助,

彼得