Skip to content

Commit d39a99d

Browse files
Add serialization_options
Prior to 0.9, @options was used to see the options passed to to_json. For some reason, with 0.9 the options were no longer passed and were entirely inaccessible within a Serializer. This restores the access by placing it in an attribute named serializer_options.
1 parent 784eccd commit d39a99d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/active_model/serializable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def self.included(base)
99
def as_json(options={})
1010
instrument('!serialize') do
1111
if root = options.fetch(:root, json_key)
12-
hash = { root => serializable_object }
12+
hash = { root => serializable_object(options) }
1313
hash.merge!(serializable_data)
1414
hash
1515
else
16-
serializable_object
16+
serializable_object(options)
1717
end
1818
end
1919
end

lib/active_model/serializer.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ def convert_keys(hash)
273273
end]
274274
end
275275

276+
attr_accessor :serialization_options
277+
276278
def serializable_object(options={})
279+
self.serialization_options = options
277280
return @wrap_in_array ? [] : nil if @object.nil?
278281
hash = attributes
279282
hash.merge! associations

0 commit comments

Comments
 (0)