【发布时间】:2015-03-16 15:30:14
【问题描述】:
我在控制器方法中有一个更大的 JSON 响应:
render json: {
user: { id: @current_user.id,
name: @current_user.full_name,
title: @current_user.title,
phone_work: @current_user.phone_work,
phone_mobile: @current_user.phone_mobile,
addresses: @current_user.addresses },
appointments: @current_user.appointments
}
我尝试执行 AppointmentSerializer.new(@current_user.appointments) 并收到此错误:undefined method 'read_attribute_for_serialization'。错误来自第一行,其中呈现了 json (render json:)。
如何为用户、用户地址和约会指定不同的序列化程序?
【问题讨论】:
标签: ruby-on-rails json active-model-serializers