rails/strong_parameters — pull request #86 by HurricaneJames (2013-01-21 21:02:08+00:00)
Title: Nested Attributes: use accepts_nested_attributes_for without fields_for

Occasionally, I want forms that that do not use fields_for and array of some association. For example, when I do not want the meaningless fields_attributes[0][attribute] syntax, but instead something more parseable like fields_attributes[name][attribute]. Since the model ignores the key values anyway, this works just fine without strong_parameters. However, I notice that strong_parameters goes out of its way to assume everybody will be using fields_for.

lib/action_controller/parameters.rb line 183-84:

# fields_for on an array of records uses numeric hash keys.
elsif value.is_a?(Hash) && value.keys.all? { |k| k =~ /\A-?\d+\z/ }

Was there some reason for doing the extra hash keys check? I didn't see one, but I also spent less than 10 minutes looking at the code. If there was not some reason to check for numeric hash keys, this patch will allow generic attribute index keys to work.