Skip to content

Instantly share code, notes, and snippets.

@kernow
Last active December 18, 2015 03:59
Show Gist options
  • Save kernow/5721604 to your computer and use it in GitHub Desktop.
Save kernow/5721604 to your computer and use it in GitHub Desktop.
config.middleware.insert_after Warden::Manager, Dragonfly::Middleware, :reports
config.middleware.insert_after Rack::Cache, Dragonfly::Middleware, :images
# File uploads
file_app = Dragonfly[:reports]
file_app.configure_with(:rails)
file_app.define_macro(ActiveRecord::Base, :file_accessor)
file_app.configure do |config|
config.server.before_serve do |job, env|
Rails.logger.info "************** in file before_serve"
unless env['warden'] && env['warden'].user && env['warden'].user.has_admin_role?
# Prevent direct access to file urls
throw :halt, [404, { 'Content-type' => 'text/plain' }, ['The content you are trying to access does not exist']]
end
end
end
# require 'dragonfly/rails/images'
# Regular image uploads
image_app = Dragonfly[:images]
image_app.configure_with(:rails)
image_app.configure_with(:imagemagick)
image_app.define_macro(ActiveRecord::Base, :image_accessor)
image_app.configure do |config|
config.server.before_serve do |job, env|
Rails.logger.info "************** in image before_serve"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment