Skip to content

Latest commit

 

History

History
91 lines (59 loc) · 2.69 KB

README.rdoc

File metadata and controls

91 lines (59 loc) · 2.69 KB

About Paperclip Dragonfly

It’s a rail engine that loads dragonfly gem adding scope and id_partion storing style. It let paperclip users to migrate to this solution when require more image size flexibility without loosing this file storing structure.

Dragonfly store files using the current time, but for paperclip you can make Dragonfly to save files at :scope/:id_partition

class User < ActiveRecord::Base
  dragonfly_for :avatar_file, :scope => 'avatars'
end

Path style can be defined as follows

*System defined path styles

System defined available style’s are: :id_partition or :time_partition

class User < ActiveRecord::Base
  dragonfly_for :avatar_file, :scope => 'avatars', :path_style => :id_partiton
end

*Custom path style

You can define your own custom path style’s with the following variables

** :scope ** :id ** :id_partition ** :time_partition

class User < ActiveRecord::Base
  dragonfly_for :avatar_file, :scope => 'avatars', :custom_path_style => ':scope/:id/original'
end

User avatar files will be stored as /avatars/000/000/001/filename_original.jpg

class Image < ActiveRecord::Base
  dragonfly_for :file # scope defaults to 'images'
end

Image files will be stored as /images/000/000/001/filename_original.jpg

Basic configuration

Rails Gemfile dependencies

gem 'paperclip_dragonfly', :git => 'https://github.com/ritxi/paperclip-dragonfly.git'

App configuration (config/application.rb)

config.paperclip_dragonfly.security_key = 'mysecretkey'
config.paperclip_dragonfly.protect_from_dos_attacks = true
config.paperclip_dragonfly.route_path = 'media' # /media

# Default is Rails.root.join('public','assets'), this will only be used on local development environment, I expect production to use amazon and heroku
config.paperclip_dragonfly.assets_path = 'local/path/where/assets/should/be/stored'

Model setup

Default Images scope is good for you?

class Image < ActiveRecord::Base
  dragonfly_for :file # scope defaults to 'images'
end

# Add the following migration to your images migration file or add a new migration adding the file_uid field
create_table "images", :force => true do |t|
  ...
  t.column "file_uid", :string
end

Prefere custom scope?

class User < ActiveRecord::Base
  dragonfly_for :avatar_file, :scope => 'avatars'
end

# Add the following migration to your images migration file or add a new migration adding the avatar_file_uid field
create_table "users", :force => true do |t|
  ...
  t.column "avatar_file_uid", :string
end

Paperclip migration

Create a rake task with / Run the following code

User.each do |u|
  u.create_dragonfly_uid(:avatar_file_uid, :paper_clip_accessor)
end