Skip to content

Commit 89448a7

Browse files
committed
remove useless conditionals
`element` can never be a hash because: 1. `slice` returns a Parameters object and calls each on it: https://github.com/rails/rails/blob/cb3f25593b1137e344086364d4b1a52c08e8eb3b/actionpack/lib/action_controller/metal/strong_parameters.rb#L656 2. `each` which is implemented by `each_pair` will call `convert_hashes_to_parameters` on the value: https://github.com/rails/rails/blob/cb3f25593b1137e344086364d4b1a52c08e8eb3b/actionpack/lib/action_controller/metal/strong_parameters.rb#L192-197 3. `convert_hashes_to_parameters` will convert any hash objects in to parameters objects: https://github.com/rails/rails/blob/cb3f25593b1137e344086364d4b1a52c08e8eb3b/actionpack/lib/action_controller/metal/strong_parameters.rb#L550-566
1 parent cb3f255 commit 89448a7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

actionpack/lib/action_controller/metal/strong_parameters.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def each_element(object)
578578
end
579579

580580
def fields_for_style?(object)
581-
(object.is_a?(Hash) || object.is_a?(Parameters)) &&
581+
object.is_a?(Parameters) &&
582582
object.to_unsafe_h.all? { |k, v| k =~ /\A-?\d+\z/ && v.is_a?(Hash) }
583583
end
584584

@@ -665,7 +665,7 @@ def hash_filter(params, filter)
665665
else
666666
# Declaration { user: :name } or { user: [:name, :age, { address: ... }] }.
667667
params[key] = each_element(value) do |element|
668-
if element.is_a?(Hash) || element.is_a?(Parameters)
668+
if element.is_a?(Parameters)
669669
element = self.class.new(element) unless element.respond_to?(:permit)
670670
element.permit(*Array.wrap(filter[key]))
671671
end

0 commit comments

Comments
 (0)