Skip to content

Rails engine for attachment management through Dropzone.js and Dragonfly

License

Notifications You must be signed in to change notification settings

tommasop/attach_it

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AttachIt

Installation

In your Gemfile

gem 'attach_it', github: 'tommasop/attach_it', branch: 'master'
  1. Mount engine in routes.rb
  mount AttachIt::Engine, at: "/attach_it"
  1. Add attach_it js and css to application
  2. Generate migrations and migrate
  rake attach_it:install:migrations
  rake db:migrate
  1. Add attacheable to your models:
  include AttachIt::Attacheable
  1. Add partial, to show and add files to your view
  <%= render "attach_it/attached_files/add_files", attached_model: @actual_model  %>

Active Admin Integration

  1. Add attach_it js and css to application

  2. Add partial to show and add files to your activeadmin view

  show do
    render 'admin/shared/show', model: actual_model
  end 

Something Fancier

The migration file adds an attachment_type string column to the attachment table.

This allows you to have multiple has_* from your model to the AttachIt::AttachmentFile one.

So for example if you need to have n documents and one image you can do something along this lines:

MyModel < ActiveRecord::Base
  # Multiple Documents
  include AttachIt::Attacheable
  # The image
  has_one :image, -> { where attachment_type: 'the_image' }, class_name: "AttachIt::AttachedFile", as: :attacheable,  dependent: :destroy
  accepts_nested_attributes_for :image, allow_destroy: true 
end

This project rocks and uses MIT-LICENSE.

About

Rails engine for attachment management through Dropzone.js and Dragonfly

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published