Is there a way I can pass options to new version of AMS like this answer shows?
Asked
Active
Viewed 303 times
1 Answers
2
You can parse options Hash
when creating a new instance of a serializer, but the only attribute it will use is the :root
as you can see on ActiveModel::Serializer
source code:
def initialize(object, options = {})
@object = object
@root = options[:root] || (self.class._root ? self.class.root_name : false)
end
You can override this method on you Serializer class and use the rest of the options as you wish:
class PostSerializer < ActiveModel::Serializer
attributes :title, :body
def initialize(object, options = {})
super(object, options)
# Your custom code goes here
end
end

gizotti
- 126
- 5