Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 蜻蜓宝石-默认图像?_Ruby On Rails_Ruby On Rails 3_Rmagick_Dragonfly Gem - Fatal编程技术网

Ruby on rails 蜻蜓宝石-默认图像?

Ruby on rails 蜻蜓宝石-默认图像?,ruby-on-rails,ruby-on-rails-3,rmagick,dragonfly-gem,Ruby On Rails,Ruby On Rails 3,Rmagick,Dragonfly Gem,我使用的是蜻蜓,希望有一个默认的图像,可以像现在的缩略图一样调整大小 我目前有以下代码,但当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.t

我使用的是蜻蜓,希望有一个默认的图像,可以像现在的缩略图一样调整大小

我目前有以下代码,但当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"

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

您需要将配置值'allow_fetch_file'设置为true-出于安全考虑,通过服务器使用fetch_file进行请求在默认情况下处于关闭状态(除以下情况外,没有特别说明: 但是,如果您这样做,您可能应该再次为安全起见,将“protect_from_dos_attacks”(保护_免受_dos_攻击)设置为true:

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

希望这对我有所帮助,我首先添加了Mark提供的配置代码,从而解决了这个问题

然后,我的日志中出现了以下错误:

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.

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

class Photo
  dragonfly_accessor :image do
    default 'public/images/default.png'
  end
end

查看文档:

Hi Mark,谢谢你的回复。这听起来应该有效,但我看不到任何变化。“秘密”应该是特定的吗?我刚刚输入了一个随机字符串。秘密应该是只有你知道的任何随机字符串。现在似乎有一个默认选项:
class Photo
  dragonfly_accessor :image do
    default 'public/images/default.png'
  end
end