In your Gemfile
gem 'attach_it', github: 'tommasop/attach_it', branch: 'master'
- Mount engine in
routes.rb
mount AttachIt::Engine, at: "/attach_it"
- Add attach_it js and css to application
- Generate migrations and migrate
rake attach_it:install:migrations
rake db:migrate
- Add attacheable to your models:
include AttachIt::Attacheable
- Add partial, to show and add files to your view
<%= render "attach_it/attached_files/add_files", attached_model: @actual_model %>
-
Add attach_it js and css to application
-
Add partial to show and add files to your activeadmin view
show do
render 'admin/shared/show', model: actual_model
end
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.