strong_form 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a30f0f44d553fb9d707018abd5d9d55aa03ec1dd
4
- data.tar.gz: b8ce403abbfdf3a12aeb68872b3ef7773db66ec5
3
+ metadata.gz: ff15586ac89816f64ef1c81905617927482828df
4
+ data.tar.gz: b481ed6c8aaff01a061bc8651398312a32d84ce3
5
5
  SHA512:
6
- metadata.gz: 8a2a3ec614c3b8e1aef6703421a7ae931e2180d922db010318a12c5e494a754bf8b8b76baea275d15b95825651271105b63a0d45ab5bddb7c0165910064d755a
7
- data.tar.gz: b5a489bc2673f013f1d93aa63872c473e26ddc912c5286f2bc1cf289a8e4c6b367297e1d9d6844c82c0488185356d8fc0b04368ca46a6c9ef22a61f57083846d
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
@@ -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
- # explicilty passed
11
- if options.key?(:permitted_attributes)
12
- self._strong_form_permitted_attributes = options.delete(:permitted_attributes)
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 _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]
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)
@@ -1,3 +1,3 @@
1
1
  module StrongForm
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -3,4 +3,5 @@ class Address < ActiveRecord::Base
3
3
 
4
4
  has_many :tags, as: :taggable
5
5
  accepts_nested_attributes_for :tags
6
+ accepts_nested_attributes_for :user
6
7
  end
@@ -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: %i(street) do |af|
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