Sha256: 9bf97a01896cedd1aad99b4964be87802bf4ec33bb9408aacae286af0dc5c8d9

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

Using With Rails 3
==================

Setting up the quick way
------------------------
config/initializers/dragonfly.rb:

    require 'dragonfly/rails/images'

Setting up the more explicit way
--------------------------------
You can do the above explicitly.

config/initializers/dragonfly.rb:

    require 'dragonfly'

    app = Dragonfly[:images]
    app.configure_with(:imagemagick)
    app.configure_with(:rails)

    app.define_macro(ActiveRecord::Base, :image_accessor)

application.rb:

    config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images, '/media'
    config.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"
    }

Gemfile
-------

    gem 'dragonfly', '~>0.8.1'
    gem 'rack-cache', :require => 'rack/cache'

Capistrano
----------
If using Capistrano with the above, you probably will want to keep the cache between deploys, so in deploy.rb:

    namespace :dragonfly do
      desc "Symlink the Rack::Cache files"
      task :symlink, :roles => [:app] do
        run "mkdir -p #{shared_path}/tmp/dragonfly && ln -nfs #{shared_path}/tmp/dragonfly #{release_path}/tmp/dragonfly"
      end
    end
    after 'deploy:update_code', 'dragonfly:symlink'

Use it!
-------

To see what you can do with the model accessors, see {file:Models}.

Mounting in routes.rb
---------------------
Instead of mounting as a middleware, you could skip that bit and mount directly in the routes.rb file:

    match '/media(/:dragonfly)', :to => Dragonfly[:images]

Make sure the the path prefix matches the Dragonfly app's configured url_path_prefix (which is /media by default for Rails).

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
dragonfly-0.8.4 extra_docs/Rails3.md
fog-dragonfly-0.8.2 extra_docs/Rails3.md
dragonfly-0.8.2 extra_docs/Rails3.md
fog-dragonfly-0.8.1 extra_docs/Rails3.md
dragonfly-0.8.1 extra_docs/Rails3.md