I am trying to upgrade to the active_model_serializers 0.10.x gem.
But I am getting an error:
can't add a new key into hash during iteration
Here are the relevant portions of code:
respond_to do |format|
format.html # show.html.erb
format.json { render json: @shows, each_serializer: ShowSerializer, meta: @shows.total_count, meta_key: 'count' }
end
Serializer:
class ShowSerializer < ActiveModel::Serializer
def attributes(*args)
data = super
performances = object.performances.order("billing_index ASC")
display_limit = 7
data[:performances] = ActiveModel::Serializer::ArraySerializer.new(performances.limit(display_limit), each_serializer: PerformanceSerializer, scope: self.scope)
data
end
end
I do not use
has_many :performances
because I want to limit the performances to first 7.