Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dragonfly gem - default images?

I'm using Dragonfly and would like to have a default image that resizes in the same way present thumbnails do.

I currently have the following code, but when Dragonfly uses the fetch_file method, it tries to process a thumbnail but the resulting URL is a dead link.

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"

I can't find much help on line for this, so any hints are most appreciated! Thanks!

like image 441
Blake Simpson Avatar asked Dec 28 '22 15:12

Blake Simpson


1 Answers

you need to set the config value 'allow_fetch_file' to true - requesting over the server using fetch_file is turned off by default for security (this isn't documented particularly except for here: http://markevans.github.com/dragonfly/Dragonfly/Server.html If you do this, however, you should probably turn on 'protect_from_dos_attacks' to true, again for security:

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

Hope that helps

like image 104
Mark Evans Avatar answered Jan 07 '23 22:01

Mark Evans