【发布时间】:2015-02-25 02:11:28
【问题描述】:
说我有这个序列化器
class FooSerializer < ActiveModel::Serializer
attributes :this, :that, :the_other
def this
SomeThing.expensive(this)
end
def that
SomeThing.expensive(that)
end
def the_other
SomeThing.expensive(the_other)
end
end
单个序列化值的操作有些昂贵...
然后我有另一个序列化程序可以使用它,但不返回所有成员:
class BarSerializer < FooSerializr
attributes :the_other
end
这不起作用... BarSerializer 仍然会拥有 this、that 和 the_other...
如何利用继承但不能自动获得相同的属性?我正在寻找模块 mixins 以外的解决方案。
【问题讨论】:
标签: ruby-on-rails active-model-serializers