【发布时间】:2018-12-20 18:05:21
【问题描述】:
我正在尝试在我的 API 中使用 ActiveModelSerializer。除了 BusinessCategory 关系之外,一切似乎都有效。它只是显示了那个 id。我希望它显示所有属性。我不确定它是否使用了序列化程序,因为当我删除关系时它仍然会出现。
PerksSerializer
class PerksSerializer < ActiveModel::Serializer
attributes :id, :status, :scope, :business_name, :business_description, :business_address_street,
:business_address_state, :business_address_city, :business_address_postal_code,
:business_website, :latitude, :longitude, :headline, :description, :start_date, :end_date,
:redemption_instructions, :cashier_instructions, :redemption_button_text, :claim_type,
:business_manager_approved_by, :created_at
belongs_to :primary_business_category
belongs_to :secondary_business_category
end
PerksController
def index
data = property.available_perks
render json: data
end
BusinessCategorySerializer
class BusinessCategorySerializer < ActiveModel::Serializer
attributes :name, :description
end
【问题讨论】:
标签: ruby-on-rails ruby active-model-serializers