This plugin makes Dragonfly works with MongoMapper like it works with ActiveRecord
Install:
script/plugin install git://[email protected]:tomasc/dragonfly_mongo_mapper_extensions.git
Configure:
config/initializers/dragonfly.rb
require 'dragonfly' require 'dragonfly_mongo_mapper_extensions' require 'rack/cache'
app = Dragonfly::App[:images]
# MongoMapper extensions MongoMapper::Document::InstanceMethods.module_eval do def self.included(base) base.extend Dragonfly::MongoMapperExtensions::ClassMethods base.send :include, Dragonfly::MongoMapperExtensions::InstanceMethods base.register_dragonfly_app :image, Dragonfly::App[:images] end end
# Dragonfly config app.configure_with(Dragonfly::Config::RMagickImages) app.configure_with(Dragonfly::Config::RailsDefaults) app.datastore = Dragonfly::DataStorage::MongoGridFsStore.new( MongoMapper.connection.host, MongoMapper.database.name )
# Dragonfly Middleware middleware = Rails.respond_to?(:application) ? Rails.application.middleware : ActionController::Dispatcher.middleware middleware.insert_after Rack::Lock, Dragonfly::Middleware, :images
# Rack Cache middleware.insert_before Dragonfly::Middleware, Rack::Cache, { :verbose => true, :metastore => "file:#{Rails.root}/tmp/dragonfly/cache/meta", :entitystore => "file:#{Rails.root}/tmp/dragonfly/cache/body" }
class User include Mongoid::Document
field :name field :email
image_accessor :avatar end
Notice you don’t need to declare avatar_uid
field, the extension defines this field automatically.
based on Wilker Lúcio’s dragonfly_mongoid_extensions http://github.com/wilkerlucio/dragonfly_mongoid_extensions.git
Simple modification of rails/init.rb to check that Dragonfly::DataStorage::Base is available before requiring the plugin.