Skip to content

Instantly share code, notes, and snippets.

Created December 27, 2012 23:18
Show Gist options
  • Save anonymous/4393062 to your computer and use it in GitHub Desktop.
Save anonymous/4393062 to your computer and use it in GitHub Desktop.
Dragonfly patch to fall back to a default image when the original is not found.
if Rails.env.development?
module Dragonfly
module DataStorage
class FileDataStore
def retrieve(relative_path)
validate_uid!(relative_path)
path = absolute(relative_path)
pathname = Pathname.new(path)
if !pathname.exist?
pathname = Pathname.new('/path/to/default-image.jpg')
end
raise DataNotFound, "couldn't find file #{ENV['RAILS_ROOT']}" unless pathname.exist?
[
pathname,
(store_meta ? retrieve_meta_data(path) : {})
]
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment