2つのモデルを組み合わせて並べ替え、その結果をシリアライザに公開したいと思います。Rails APIシリアライザ
ので、私のユーザーコントローラに私が
#users_controller.rb
def transactions
@debit = current_user.debits.all
@credit = current_user.credits.all
@history = [@debit, @credit].flatten
@sorted_history = @history.sort_by { |item| item.created_at.strftime('%m/%d/%y') }
render json: UserTransactionSerializer.new(@sorted_history).call
end
と私のシリアライザ上を持っている私が持っている:
module Api
module V1
class UserTransactionSerializer < BaseSerializer
def call
{
id: object.id,
amount: object.amount,
status: object.status,
created_at: object.created_at.iso8601
}
end
end
end
end
を私が怒鳴る、このエラーを取得しています:
NoMethodError (undefined method `id' for #<Array:0x0055ce49b57b20>)
EDIT:誤植を