首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >蜻蜓宝石-默认图像?

蜻蜓宝石-默认图像?
EN

Stack Overflow用户
提问于 2011-08-17 16:54:13
回答 3查看 2.7K关注 0票数 4

我使用蜻蜓,并希望有一个默认的图像,大小大小与现在的缩略图一样。

我现在有以下代码,但是当蜻蜓使用fetch_file方法时,它尝试处理一个缩略图,但是得到的URL是一个死链接。

代码语言:javascript
复制
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"

我在网上找不到多少帮助,所以任何提示都是非常感谢的!谢谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-08-19 08:43:32

通过首先添加Mark提供的配置代码,我成功地解决了这个问题。

然后,我在日志中得到了这个错误:

代码语言:javascript
复制
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似乎不能使用相对于项目的路径名称,所以我不得不指定一个绝对路径。如下所示:

代码语言:javascript
复制
img = Dragonfly[:images].fetch_file(File.join(Rails.root, 'public', 'toekomst', 'images', 'speech-bubble.png'))
票数 1
EN

Stack Overflow用户

发布于 2011-08-18 22:49:32

您需要将配置值'allow_fetch_file‘设置为true --默认情况下,为了安全起见,关闭对服务器使用fetch_file的请求(除了这里:http://markevans.github.com/dragonfly/Dragonfly/Server.html之外,没有特别说明:http://markevans.github.com/dragonfly/Dragonfly/Server.html,但是如果这样做,您可能应该将'protect_from_dos_attacks’打开为true,同样也是为了安全性:

代码语言:javascript
复制
Dragonfly[:images].configure do |c|
  # ...
  c.allow_fetch_file = true
  c.protect_from_dos_attacks = true
  c.secret = "some secret here..."
end

希望这有帮助

票数 6
EN

Stack Overflow用户

发布于 2014-10-29 16:24:42

可以使用模型访问器设置默认映像:

代码语言:javascript
复制
class Photo
  dragonfly_accessor :image do
    default 'public/images/default.png'
  end
end

见docs:http://markevans.github.io/dragonfly/models/#default-content

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7096597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档