Project

damselfly

0.0
No release in over 3 years
Low commit activity in last 3 years
Rails engine to add polymorphic file attachments leveraging dragonfly and counting references to avoid duplicates..
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 3.2.13
 Project Readme

Damselfly

Damselfly is a Rails engine to add polymorphic file attachments leveraging dragonfly and counting references to avoid duplicates.

Installation

Your rails application should be using Dragonfly. If it's not, then follow its instructions to install and configure it, then come back here. Add Damselfly to your Gemfile:

gem 'damselfly'

Usage

Grab one of your models and include the Damselfly module, then declare any attachments you need:

class Person < ActiveRecord::Base
  include Damselfly
  has_one_attached :avatar
  has_many_attached :photos
end

Internally, Damselfly treats singular attachments like a has_one association, and plural ones as a has_many. Just assign the data attribute to your attachment_attributes, like so:

@john = Person.create!(name: "John", avatar_attributes: {data: Rails.root.join('sample.jpg')}, photos_attributes: [{data: Rails.root.join('another_sample.jpg')}])

That's all. You can now access @john.avatar or @john.photos as you would do with a model that uses dragonfly.

License

This project rocks and uses MIT-LICENSE.