[英]Serialize array/relation with attributes using ActiveModel::Serializer
[英]ActiveModel Serializer: access attributes as methods
如何將序列化程序中定義的屬性作為方法訪問?
class Test < ActiveModel::Serializer
attributes :a, :b, :c
end
s = Test.new(Object)
s.a
我需要進行委派,它以前在版本0.8 /中可用
屬性方法不再在序列化程序上定義,而必須通過對象顯式訪問
class MySerializer
attributes :foo, :bar
def foo
bar + 1 # bar does not work, needs to be object.bar in 0.10
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.