2011-08-17 142 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

秘密应该是任何随机字符串只知道你 –