diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb index 3751e4a741dd2..6d8fd21814768 100644 --- a/activemodel/lib/active_model/serialization.rb +++ b/activemodel/lib/active_model/serialization.rb @@ -74,7 +74,7 @@ module Serialization def serializable_hash(options = nil) options ||= {} - attribute_names = attributes.keys.sort + attribute_names = attributes.keys if only = options[:only] attribute_names &= Array(only).map(&:to_s) elsif except = options[:except]