我有以下兩個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