strong_form 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/strong_form/form.rb +14 -7
- data/lib/strong_form/version.rb +1 -1
- data/spec/dummy/app/controllers/base_controller.rb +6 -0
- data/spec/dummy/app/views/base/fields_for_explicit.html.haml +8 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +3300 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/E6haN18CCNhwDqtCBl2Mpdw36x9r9ueGqUWs5VkbbTU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/GqaM_izIT4HEPtrrNPj4ANWSh8woB-_LdCA8qnBAd68.cache +1 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/HhLqAaTvuYuwgjUND4mK5eBePxjyKPD64_aN_YMacfI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/NAGh3C2mQEdEaSImUSF06RDZMijLl6U8J2gcPr98NBQ.cache +1 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +3 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/QAU-vbHgg5D5c2OqGQEbvMqbF8DrpkBBYysiKXPtnTU.cache +1 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/TiYC0B8qsZlVddPO1rQyU-8_89k5BCfzYKeyNrvdP5U.cache +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/VguhC2w9-v1gjhSO3Ebw85Km_5BpzzIOPF-U1DXsJGA.cache +1 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/WdRXDAtbmRw9NcGpokami_cV1EmCGTdVQtM81zUAAK4.cache +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/_755PJXlyHuPZVD39OTDgPWSWiMVLQtyH5LNgULt-8o.cache +1 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +3 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/wSf8vKqXPWbfIazZqmHp1Vxib6afMKucOf0932u3eI8.cache +1 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/yOB9v7Yv4mV6xh92Y_4FWXIorQHkty60pktkCG4Tx5k.cache +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/zZx1C1nvQBmUxUZz7VTS6ifX81mMFt1JqGwLPPaGL8E.cache +1 -0
- data/spec/examples.txt +57 -53
- data/spec/features/strong_form_spec.rb +21 -0
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6626016366a5ba97f7bcaa7fac2477926c1a7375
|
4
|
+
data.tar.gz: 5fcc3a6cbbcb4cd8a1c935fb2c7f1a501d6442b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba49e910f1db4bae7ca1a0441e6c39aad3e4d7829419a3f489000ed8e70d588cf09f624a7d91140d1000f26db89937c3fd91dd94068e0f8c9682edcdaf931c07
|
7
|
+
data.tar.gz: ac81fb50f77cf8c4cd05d28e17dd305908e89411cd4ba2a60a615a0aa4fe9b0b63d51c8d8ab6e746bb3cff7aa59075b9aa6d8fe2399ccfe2e7fcb7e30ef45d31
|
data/CHANGELOG.md
CHANGED
data/lib/strong_form/form.rb
CHANGED
@@ -6,14 +6,15 @@ module ActionView
|
|
6
6
|
attr_accessor :_strong_form_permitted_attributes
|
7
7
|
|
8
8
|
def form_for(record, options = {}, &block)
|
9
|
+
object = record.is_a?(Array) ? record.last : record
|
9
10
|
# explicilty passed
|
10
11
|
if options.key?(:permitted_attributes)
|
11
12
|
self._strong_form_permitted_attributes = options.delete(:permitted_attributes)
|
12
|
-
|
13
|
-
_strong_form_permitted_attributes if
|
13
|
+
object.permitted_attributes =
|
14
|
+
_strong_form_permitted_attributes if object.respond_to?(:permitted_attributes=)
|
14
15
|
# assigned to object
|
15
|
-
elsif
|
16
|
-
self._strong_form_permitted_attributes =
|
16
|
+
elsif object.respond_to?(:permitted_attributes)
|
17
|
+
self._strong_form_permitted_attributes = object.permitted_attributes
|
17
18
|
end
|
18
19
|
|
19
20
|
orig_form_for(record, options, &block)
|
@@ -44,9 +45,15 @@ module ActionView
|
|
44
45
|
|
45
46
|
# https://github.com/rails/rails/blob/4-2-stable/actionview/lib/action_view/helpers/form_helper.rb#L712
|
46
47
|
def fields_for(record_name, record_object = nil, options = {}, &block)
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
if _strong_form_permitted_attributes &&
|
49
|
+
record_object.respond_to?(:permitted_attributes=) &&
|
50
|
+
record_object.permitted_attributes.nil?
|
51
|
+
assign_child_permitted_attributes!(
|
52
|
+
record_name, record_object, options[:parent_builder].object.permitted_attributes
|
53
|
+
)
|
54
|
+
elsif options.key?(:permitted_attributes) && record_object.respond_to?(:permitted_attributes=)
|
55
|
+
record_object.permitted_attributes = options[:permitted_attributes]
|
56
|
+
end
|
50
57
|
|
51
58
|
builder = instantiate_builder(record_name, record_object, options)
|
52
59
|
capture(builder, &block)
|
data/lib/strong_form/version.rb
CHANGED
@@ -11,6 +11,12 @@ class BaseController < ApplicationController
|
|
11
11
|
@user.build_tag
|
12
12
|
end
|
13
13
|
|
14
|
+
def fields_for_explicit
|
15
|
+
@user = User.new
|
16
|
+
@user.addresses.build
|
17
|
+
@user.build_tag
|
18
|
+
end
|
19
|
+
|
14
20
|
def deep_fields_for
|
15
21
|
@user = User.new
|
16
22
|
(@user.addresses.build).tags.build
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|