我想做同样的伎俩 - https://robots.thoughtbot.com/fast-json-apis-in-rails-with-key-based-caches-and,但是在AMS 0.10.0.rc中无法做到,因为AMS现在没有#serializable_hash方法。
你建议做什么?
答案 0 :(得分:1)
Updated to the new version of active_model_serializers
:
class BusinessDistanceSerializer < ActiveModel::Serializer
attributes :distance
def attributes options = {}, reload = false
data = super
data.reverse_merge! ActiveModel::Serializer.adapter.new(BusinessSerializer.new(object)).serializable_hash
data
end
end
Notice the reload = false
argument.
答案 1 :(得分:0)
我正是这样做的。
class BusinessDistanceSerializer < ActiveModel::Serializer
attributes :distance
def attributes options = {}
data = super
data.reverse_merge! ActiveModel::Serializer.adapter.new(BusinessSerializer.new(object)).serializable_hash
data
end
end