diff --git a/README.md b/README.md
index c1d4c90..caadbfb 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,10 @@
Easy to use integration of drag&drop files upload via [dropzone.js](http://www.dropzonejs.com) for [ActiveAdmin](http://www.activeadmin.info).
+## History
+
+* 28.09.2015 - change model association: delete self-writed association, add `accepts_nested_attributes_for`.
+
## Requirements
* [ActiveAdmin](http://www.activeadmin.info);
@@ -13,20 +17,32 @@ Easy to use integration of drag&drop files upload via [dropzone.js](http://www.d
Add line to your Gemfile:
- gem 'activeadmin-dropzone', '~> 0.2.1'
+ gem 'activeadmin-dropzone', github: 'farpostdesign/activeadmin-dropzone'
-Add `dropzone` to your file container's class:
+Add `dropzone_item` to your file's class:
- class Post
- dropzone :images
+ class Image
+ dropzone_item container_id: :page_id
end
-Add `dropzone_item` to your file's class:
+Add method `title` in the model if there is no such attribute:
class Image
- dropzone_item
+ has_attached_file :file
+
+ def title
+ file_file_name
+ end
end
+Add permitions to `permit_params` method for your Active Admin file, for example:
+
+ permit_params :title,
+ :annotation,
+ :description,
+ ...,
+ images_attributes: [:id, :title, :position, :_destroy] # for model Image
+
Add `input` to your ActiveAdmin form:
f.input :images, as: :dropzone
@@ -43,7 +59,9 @@ You can customize columns used for upload by passing `Hash` to the `dropzone_ite
position: :position,
data: :data,
file_size: :data_file_size,
- url: :data_url
+ url: :data_url,
+ container_type: :page_type, # only for polymorphic associations!
+ container_id: :page_id, # required!
## Contributing to activeadmin-dropzone
diff --git a/app/helpers/active_admin/view_helpers/dropzone_helper.rb b/app/helpers/active_admin/view_helpers/dropzone_helper.rb
index b5ee203..030a8fc 100644
--- a/app/helpers/active_admin/view_helpers/dropzone_helper.rb
+++ b/app/helpers/active_admin/view_helpers/dropzone_helper.rb
@@ -1,12 +1,13 @@
module ActiveAdmin::ViewHelpers::DropzoneHelper
def render_mock_dropzone_files(dropzone_objects)
- dropzone_objects.map do |dropzone_object|
+ dropzone_objects.map.with_index do |dropzone_object, index|
{
id: dropzone_object.id,
name: dropzone_object.send(dropzone_object.class.dropzone_field(:title)).squish,
size: dropzone_object.send(dropzone_object.class.dropzone_field(:file_size)),
- url: dropzone_object.send(dropzone_object.class.dropzone_field(:url))
+ url: dropzone_object.send(dropzone_object.class.dropzone_field(:url)),
+ index: index,
}
end.to_json.html_safe
end
diff --git a/app/views/application/_dropzone.html.erb b/app/views/application/_dropzone.html.erb
index 8a8c458..66a1a59 100644
--- a/app/views/application/_dropzone.html.erb
+++ b/app/views/application/_dropzone.html.erb
@@ -1,8 +1,7 @@