2011-08-17 139 views
4

我正在使用蜻蜓,並希望有一個默認圖像,以縮略圖的相同方式調整大小。蜻蜓寶石 - 默認圖片?

我目前有以下代碼,但是當Dragonfly使用fetch_file方法時,它會嘗試處理縮略圖,但生成的URL是無效鏈接。

if listing.image 
    image = listing.image.jpg 
else 
    image = Dragonfly[:images].fetch_file('/toekomst/images/speech-bubble.png') 
end 
image_tag image.jpg.thumb(size).url, :class => "framed" 

我找不到對此的很多幫助,所以任何提示都非常感謝!謝謝!

+0

似乎有一個默認選項現在:HTTP:// markevans .github.io /蜻蜓/模型/#默認內容 – Chloe

回答

1

我設法得到這個固定的:首先將馬克提供的配置代碼

。 10

我當時得到這個錯誤在我的日誌:

identify: unable to open image `/toekomst/images/speech-bubble.png': No such file or directory @ error/blob.c/OpenBlob/2584. 
identify: unable to open file `/toekomst/images/speech-bubble.png' @ error/png.c/ReadPNGImage/3079. 
[2011-08-19 10:33:51] ERROR Dragonfly::FunctionManager::UnableToHandle: None of the functions registered with #<Dragonfly::Encoder:0x00000100d66d88> were able to deal with the method call encode(#<Dragonfly::TempObject:0x00000104aa2800 pathname=#<Pathname:/toekomst/images/speech-bubble.png> >,:jpg). You may need to register one that can. 

由於ImageMagick的似乎無法使用相對於項目的路徑名,我不得不指定一個絕對路徑。就像這樣:

img = Dragonfly[:images].fetch_file(File.join(Rails.root, 'public', 'toekomst', 'images', 'speech-bubble.png')) 
6

你需要設置的配置值「allow_fetch_file」來真的 - 請求在使用fetch_file服務器在默認情況下關閉了安全性(這是不是證明特別,除了在這裏: http://markevans.github.com/dragonfly/Dragonfly/Server.html 如果你這樣做,但是,你應該對安全打開「protect_from_dos_attacks」爲真,再次:

Dragonfly[:images].configure do |c| 
    # ... 
    c.allow_fetch_file = true 
    c.protect_from_dos_attacks = true 
    c.secret = "some secret here..." 
end 

希望幫助

+0

嗨馬克,感謝您的答覆。這聽起來像應該起作用,但我看不到變化。如果「祕密」是特定的東西?我現在只是把一個隨機字符串 –

+2

祕密應該是任何隨機字符串只知道你 –