Git Product home page Git Product logo

paperclip-dragonfly's Introduction

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

paperclip-dragonfly's People

Contributors

ritxi avatar kerglis avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.