Skip to content

Commit 9817dd1

Browse files
committed
Enhance permit_attribute_names method documentation for clarity on handling object and primitive arrays
1 parent f643795 commit 9817dd1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/structured_params/type/array.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,24 @@ def serialize(value)
4545
end
4646

4747
# Get permitted parameter names for use with Strong Parameters
48+
#
49+
# Returns:
50+
# - For object arrays (value_class): nested keys from the object
51+
# Example: HobbyParams with [:name, :level]
52+
# → returns [:name, :level]
53+
# → becomes { hobbies: [:name, :level] } in Params#permit_attribute_names
54+
#
55+
# - For primitive arrays (value_type): empty array
56+
# Example: attribute :tags, :array, value_type: :string
57+
# → returns []
58+
# → becomes { tags: [] } in Params#permit_attribute_names
59+
# → finally used as params.permit(:name, { tags: [] })
60+
#
4861
#: () -> ::Array[untyped]
4962
def permit_attribute_names
5063
return @item_type.permit_attribute_names if item_type_is_structured_params_object?
5164

52-
# Primitive arrays return [] for Strong Parameters format.
53-
# Example: tags: [] allows params.permit(tags: [])
65+
# Primitive arrays return [] for Strong Parameters format
5466
[]
5567
end
5668

0 commit comments

Comments
 (0)