strong_form 0.0.6 → 0.0.8
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/CHANGELOG.md +14 -0
- data/lib/strong_form/form.rb +12 -18
- data/lib/strong_form/version.rb +1 -1
- data/spec/dummy/app/models/address.rb +1 -0
- data/spec/dummy/app/views/base/fields_for_explicit.html.haml +4 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/log/test.log +5662 -0
- data/spec/examples.txt +64 -59
- data/spec/features/strong_form_spec.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff15586ac89816f64ef1c81905617927482828df
|
4
|
+
data.tar.gz: b481ed6c8aaff01a061bc8651398312a32d84ce3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8acb2392c4bb78f8030d19ffa40233a437f92390ad4cac10ca56bfa8ef7fbbfb6ce31cfcb8efc13322c5952a5c8971eda2dea2636de4032d3baeb6db0079fd2a
|
7
|
+
data.tar.gz: 02061d6d903847ff2bcd1c4a5ba64ea96af25264116408e4fb79f21f5f7ce0188614fc33e44ce4d7f14a1d0819d0d3b240fca39fcd84138707271996d1486631
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,20 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.0.8
|
6
|
+
|
7
|
+
### Bugs fixed
|
8
|
+
|
9
|
+
* Fix typo `respond_to` --> `respond_to?`
|
10
|
+
|
11
|
+
## 0.0.7
|
12
|
+
|
13
|
+
### Bugs fixed
|
14
|
+
|
15
|
+
* Fix disabling of child attributes if only `fields_for` has permitted_attributes
|
16
|
+
|
17
|
+
* Simplify code
|
18
|
+
|
5
19
|
## 0.0.6
|
6
20
|
|
7
21
|
### Bugs fixed
|
data/lib/strong_form/form.rb
CHANGED
@@ -3,18 +3,11 @@ module ActionView
|
|
3
3
|
module FormHelper
|
4
4
|
alias_method :orig_form_for, :form_for
|
5
5
|
|
6
|
-
attr_accessor :_strong_form_permitted_attributes
|
7
|
-
|
8
6
|
def form_for(record, options = {}, &block)
|
9
7
|
object = record.is_a?(Array) ? record.last : record
|
10
|
-
|
11
|
-
if options.key?(:permitted_attributes)
|
12
|
-
|
13
|
-
object.permitted_attributes =
|
14
|
-
_strong_form_permitted_attributes if object.respond_to?(:permitted_attributes=)
|
15
|
-
# assigned to object
|
16
|
-
elsif object.respond_to?(:permitted_attributes)
|
17
|
-
self._strong_form_permitted_attributes = object.permitted_attributes
|
8
|
+
|
9
|
+
if options.key?(:permitted_attributes) && object.respond_to?(:permitted_attributes=)
|
10
|
+
object.permitted_attributes = options.delete(:permitted_attributes)
|
18
11
|
end
|
19
12
|
|
20
13
|
orig_form_for(record, options, &block)
|
@@ -45,14 +38,15 @@ module ActionView
|
|
45
38
|
|
46
39
|
# https://github.com/rails/rails/blob/4-2-stable/actionview/lib/action_view/helpers/form_helper.rb#L712
|
47
40
|
def fields_for(record_name, record_object = nil, options = {}, &block)
|
48
|
-
if
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
41
|
+
if record_object.respond_to?(:permitted_attributes=)
|
42
|
+
if options.key?(:permitted_attributes)
|
43
|
+
record_object.permitted_attributes = options[:permitted_attributes]
|
44
|
+
elsif options[:parent_builder].object.try(:permitted_attributes) &&
|
45
|
+
record_object.permitted_attributes.nil?
|
46
|
+
assign_child_permitted_attributes!(
|
47
|
+
record_name, record_object, options[:parent_builder].object.permitted_attributes
|
48
|
+
)
|
49
|
+
end
|
56
50
|
end
|
57
51
|
|
58
52
|
builder = instantiate_builder(record_name, record_object, options)
|
data/lib/strong_form/version.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
= form_for @user, url: '/somewhere' do |f|
|
2
2
|
= render 'user_fields', f: f
|
3
3
|
|
4
|
-
= f.fields_for :addresses, permitted_attributes:
|
4
|
+
= f.fields_for :addresses, permitted_attributes: [:street, user_attributes: [:last_name]] do |af|
|
5
5
|
= render 'address_fields', f: af
|
6
6
|
|
7
|
+
= af.fields_for :user, User.new do |uf|
|
8
|
+
= render 'user_fields', f: uf
|
9
|
+
|
7
10
|
= f.fields_for :tag do |tf|
|
8
11
|
= render 'tag_fields', f: tf
|
@@ -22,6 +22,6 @@ module Dummy
|
|
22
22
|
# config.i18n.default_locale = :de
|
23
23
|
|
24
24
|
# Do not swallow errors in after_commit/after_rollback callbacks.
|
25
|
-
config.active_record.raise_in_transactional_callbacks = true
|
25
|
+
# config.active_record.raise_in_transactional_callbacks = true
|
26
26
|
end
|
27
27
|
end
|