我有以下两个Serializer类。在索引控制器中,我想跳过加载project_products,只显示/编辑我想要获取project_product的详细信息的方法。ruby on rails中activemodel序列化程序的可选属性
class ProjectSerializer < ActiveModel::Serializer
attributes :id, :name, :category, :project_category_id, :status, :description
has_many :project_products
end
class ProjectProductSerializer < ActiveModel::Serializer
attributes :id, :name, :quantity
end
控制器:
def index
respond_with @projects
end
def load_projects
@projects = current_organization.projects.includes(:project_category)
end
综上所述,您不想在show/edit中加载project_products? – Defoncesko
嗨@Defoncesko正好在我想要加载project_products在显示/编辑,但不是索引 – Santi
请显示您的意见和控制器代码。 – Defoncesko