【发布时间】:2016-06-16 17:32:15
【问题描述】:
我试图限制在序列化程序级别的 json 响应中显示哪些子项。如果一种货币被标记为“活动”,则该货币应包含在商家的有效负载中。如果货币“无效”,则不应包括商家的 GET。
导轨,4.2.5 active_model_serializers, ~>0.10.0.rc3
序列化器
class MerchantSerializer < ActiveModel::Serializer
attributes :id, :merchant_name, :merchant_type, :currencies
has_many :merchant_currency_maps
end
class MerchantCurrencyMapSerializer < ActiveModel::Serializer
attributes :id, :currency, :b4flight_id, :aht_account_id, :created_at, :updated_at, :guess_merchant
end
我的尝试
我尝试过制作include_currency_maps 方法link但无济于事。
并创建显示here 的自定义属性。但我仍在努力掌握如何/应该如何做到这一点。
【问题讨论】:
标签: ruby-on-rails ruby serialization active-model-serializers