diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 8b4dc06603..c6fe0537a2 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -107,10 +107,14 @@ def include unless super || exclude if m.respond_to?(:attribute_names) && m.attribute_names.any? + self.include = m.attribute_names + if m.respond_to?(:stored_attributes) && !m.stored_attributes.empty? - self.include = m.attribute_names + m.stored_attributes.values.flatten.map(&:to_s) - else - self.include = m.attribute_names + self.include += m.stored_attributes.values.flatten.map(&:to_s) + end + + if m.respond_to?(:attribute_aliases) && m.attribute_aliases.any? + self.include += m.attribute_aliases.keys end if m.respond_to?(:nested_attributes_options) && m.nested_attributes_options.keys.any? diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb index 894a3824c0..d397244aa7 100644 --- a/actionpack/test/controller/params_wrapper_test.rb +++ b/actionpack/test/controller/params_wrapper_test.rb @@ -293,6 +293,10 @@ class SampleOne def self.attribute_names ["username"] end + + def self.attribute_aliases + { "nick" => "username" } + end end class SampleTwo @@ -328,6 +332,19 @@ def test_namespace_lookup_from_model end end + def test_namespace_lookup_from_model_alias + Admin.const_set(:User, Class.new(SampleOne)) + begin + with_default_wrapper_options do + @request.env["CONTENT_TYPE"] = "application/json" + post :parse, params: { "nick" => "sikachu", "title" => "Developer" } + assert_parameters({ "nick" => "sikachu", "title" => "Developer", "user" => { "nick" => "sikachu" } }) + end + ensure + Admin.send :remove_const, :User + end + end + def test_hierarchy_namespace_lookup_from_model Object.const_set(:User, Class.new(SampleTwo)) begin