activeadmin_polymorphic 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +22 -17
- data/lib/activeadmin_polymorphic/form_builder.rb +5 -1
- data/lib/activeadmin_polymorphic/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea40004a0a7bb3aef319d8e0b0d233b3f3321436
|
4
|
+
data.tar.gz: a51f08e75f8e5bdc1cfe67d66d9b747668e6859c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b3cb0a0b38df959b3dcd5b26b6508a8b2cf7f3d2984c0f98073a41f4f7b88a5de7cc7c61523a3269ab993bb9035d935754aea040a8e8d2a80762a9cc346840f
|
7
|
+
data.tar.gz: c10e8cfd50e7caae2ded2bf30dfa68b1c8914d170ad7bef1a6503f6682b4512802338f09c52bf3e9fc0358f459671ccc4a3ff8d20dbce6335011bed7921411cd
|
data/README.md
CHANGED
@@ -21,20 +21,25 @@ gem "activeadmin_polymorphic"
|
|
21
21
|
|
22
22
|
and run `bundle install`.
|
23
23
|
|
24
|
-
Include assets in
|
24
|
+
Include assets in JS and CSS manifests
|
25
25
|
|
26
|
+
JS:
|
26
27
|
```
|
27
28
|
#= require activeadmin_polymorphic
|
29
|
+
```
|
30
|
+
|
31
|
+
CSS:
|
32
|
+
```
|
28
33
|
@import "activeadmin_polymorphic";
|
29
34
|
```
|
30
35
|
|
31
36
|
# Usage
|
32
37
|
|
33
|
-
To use gem, your model should have related model, which works as a proxy to polymorphic relations.
|
38
|
+
To use the gem, your model should have a related model, which works as a proxy to polymorphic relations.
|
34
39
|
|
35
40
|

|
36
41
|
|
37
|
-
|
42
|
+
The gem extends activeadmin's form builder, so to enable the `has_many_polymorphic` method you need to override form builder using the `builder` option:
|
38
43
|
|
39
44
|
```
|
40
45
|
...
|
@@ -47,38 +52,38 @@ end
|
|
47
52
|
```
|
48
53
|
|
49
54
|
There are few options available:
|
50
|
-
* first option
|
51
|
-
* second option referes to polymorphied version of association name (sectionable_id and sectaionable_type for example)
|
55
|
+
* first option, the name of polymorphic has_many association
|
56
|
+
* second option, referes to polymorphied version of an association name (sectionable_id and sectaionable_type for example)
|
52
57
|
* `types` - list of related models you want to use
|
53
|
-
* `allow_destroy` -
|
58
|
+
* `allow_destroy` - whether or not to allow destroying related objects
|
54
59
|
* `sortable` - enables drag'n'drop for nested forms, accepts sortable column name, for example `sortable: :priority`
|
55
60
|
|
56
|
-
Subforms for polymorphic relations are forms which you define in your ActiveAdmin.
|
61
|
+
Subforms for polymorphic relations are forms which you define in your ActiveAdmin. The gem fetches and submits them using some ajax magic.
|
57
62
|
|
58
63
|
# Under the hood
|
59
64
|
|
60
|
-
This gem is a set of dirty hacks and tricks. Calling `polymorphic_has_many` makes it
|
65
|
+
This gem is a set of dirty hacks and tricks. Calling `polymorphic_has_many` makes it do the following things:
|
61
66
|
|
62
|
-
* for new records it generates dropdown with polymorphic types
|
63
|
-
* for exising records it generates two hidden fields with id and type
|
64
|
-
* then the real
|
65
|
-
* when you try to submit forms,
|
66
|
-
* after all
|
67
|
+
* for new records it generates a dropdown with polymorphic types
|
68
|
+
* for exising records it generates two hidden fields with `id` and `type`
|
69
|
+
* then the real JavaScript starts, it extracts whole forms from polymorphic models new or edit pages, strips form actions, and inserts those forms right into the parent form
|
70
|
+
* when you try to submit forms, JavaScript submits subforms first; if subforms are invalid, it reloads them with erros and interupts the main form's submission process
|
71
|
+
* after all subforms have been successfully saved, it strips them (because forms nested into other forms are simantically invalid, right?) and submits the parent form
|
67
72
|
|
68
73
|
# File uploads in subforms
|
69
74
|
|
70
|
-
|
75
|
+
The gem relies on [rails ajax](https://github.com/rails/jquery-rails)'s form submissions, which doesn't allow to submit files directly. Workaround for this is asynchronous file submission using, for example [remotipart](https://github.com/JangoSteve/remotipart) for CarrierWave, or [refile](https://github.com/elabs/refile) with [refile-input](https://github.com/hyperoslo/refile-input). Note: before subforms submissions JavaScript strips all file inputs from the forms.
|
71
76
|
|
72
77
|
# Testing
|
73
78
|
|
74
|
-
|
79
|
+
Test's stucture is mostly copied from the original ActiveAdmin.
|
75
80
|
|
76
|
-
Install development dependencies with `bundle install`. To setup test suit run `rake test`. Run tests with `bundle exec guard`. There aren't many of them, let's say there are quite a few.
|
81
|
+
Install development dependencies with `bundle install`. To setup the test suit run `rake test`. Run tests with `bundle exec guard`. There aren't many of them, let's say there are quite a few.
|
77
82
|
|
78
83
|
# In plan
|
79
84
|
|
80
85
|
* allow to reuse existing polymorphic objects
|
81
|
-
* check who it works with
|
86
|
+
* check who it works with: models under a certain namespace
|
82
87
|
* improve tests
|
83
88
|
|
84
89
|
# License
|
@@ -51,7 +51,11 @@ module ActiveadminPolymorphic
|
|
51
51
|
contents << has_many_form.input(builder_options[:sortable], as: :hidden)
|
52
52
|
|
53
53
|
contents << template.content_tag(:li, class: 'handle') do
|
54
|
-
|
54
|
+
'''
|
55
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="30px" height="25px" viewBox="0 0 550 550" enable-background="new 0 0 550 550" xml:space="preserve">
|
56
|
+
<path d="M418.909,456.728h-93.091v-288l-93.091,93.091V139.637L372.363,0L512,139.637v122.182l-93.091-93.091V456.728z M93.091,84.363h93.091v288l93.091-93.091v122.182L139.637,541.091L0,401.454V279.272l93.091,93.091V84.363z"></path>
|
57
|
+
</svg>
|
58
|
+
'''.html_safe
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_polymorphic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petr Sergeev
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: This gem extends formtastic's form builder to support polymoprhic has
|
15
15
|
many relations in your forms
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.4.5
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: HasMany polymoprhic support for active admin.
|