Reputation: 5565
If I have a collection of something, say Widgets, and I'm using Active Model Serializers to serialize the collection of Widgets, how do I pass instance_options to a collection?
render json: @widgets, count: 40
I tried the above and I can't seem to get count: 40
in my instance_options
. Am I missing something?
Upvotes: 0
Views: 3339
Reputation: 110
You can call @instance_options[:count]
in method of WidgetsSerializer.
In controller:
render json: @widgets, count: 40
For exmaple,
class WidgetsSerializer < ActiveModel::Serializer
attributes :count
def count
@instance_options[:count] #=> 40
end
end
Upvotes: 6