我正在尝试为 Ember 应用程序在 active_model_serializer 中侧载数据,并在尝试包含对象时得到 NoMethodError:
#Email:0x00000100d33d20 的未定义方法“对象”
它仅在 :include => true 设置时发生,如下所示:
class ContactSerializer < ActiveModel::Serializer
embed :ids, :include => true
attributes :first_name, :last_name
has_many :emails
end
我的模型如下所示:
class Contact < ActiveRecord::Base
attr_accessible :first_name, :last_name, :company,
belongs_to :account
belongs_to :user
has_many :emails
end
class Email < ActiveRecord::Base
attr_accessible :email_address, :email_type_id, :is_primary
belongs_to :contact
end
我的控制器如下所示:
def show
@contact = @current_user.contacts.where(:id => params[:id]).includes(:emails).first
render :json => @contact
end
提前致谢。