2010-12-01 50 views
0

我已經在我的模型下面的回形針設置:Paperclip.interpolates隨機沒有返回值

#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' 

爲INSTANCE_ID我有以下幾點:

Paperclip.interpolates :instance_id do |attachment, style| 

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

end 

發生了什麼事是當我第一次火起來服務器,我注意到我的圖像404s。我原以爲是亞馬遜S3,但後來我查看了這些網址,並注意到有時instance_id沒有被Paperclip.interpolates返回。

任何想法爲什麼?你有沒有經歷過這樣的事情?

感謝

+0

在哪裏你有沒有指定Paperclip.interpolates的代碼:instenace_id?因爲如果它不總是被返回,它似乎不是正確要求,並在服務器重新啓動過程中運行。 – DanneManne 2010-12-01 08:09:04

回答

2

如果我理解正確你想達到什麼樣的,那麼下面應該工作:

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

FYI:您的插值PROC定義了一個方法,但實際上並沒有做什麼...

希望這有助於

彼得

+0

謝謝,上面的作品。只有時間會告訴你是否能阻止破碎的網頁。 – AnApprentice 2010-12-01 17:53:52