Active_model_serializers: How to serialize an array?

Created on 28 Apr 2015  Â·  5Comments  Â·  Source: rails-api/active_model_serializers

I am getting the following error:

NoMethodError - undefined method `read_attribute_for_serialization' for #Array:0x007fd3e1151898

Ruby code in controller:

@results = Record.search(size: 8, query: { match: { name: { query: params[:name], operator: 'and' } } })
@records = @results.records.records << Record.last(5)
 respond_with(@records, each_serializer: RecordSerializer)

Most helpful comment

Looks like it moved to ActiveModel::Serializer::ArraySerializer.

All 5 comments

Use ArraySerializer as

ActiveModel::ArraySerializer.new(@records, each_serializer: RecordSerializer).to_json

@prasadsurase that used to be the case in 0.9.3. I'm trying to upgrade to 0.10.0.rc1 and finding that ActiveModel::ArraySerializer doesn't exist anymore…

Looks like it moved to ActiveModel::Serializer::ArraySerializer.

I fixed the problem, thanks :).

Tks everyone :smile: you're awesome
It's hard to follow up ever thread :stuck_out_tongue_closed_eyes:

Was this page helpful?
0 / 5 - 0 ratings