现在我在模型中的 as_json 方法中有以下内容:
#values we will pass to Json
def as_json(options={})
super(:only => [:name, :last_name, :age])
end
我有一个方法可以执行一些逻辑并返回一个值:
def self.full_name
self.name + self.last_name
end
如何在 as_json 中返回“选项”结果以及我已经拥有的字段?我试过这个:
#values we will pass to Json
def as_json(options={})
super(:only => [:name, :full_name => self.full_name, :last_name, :age])
end
没有运气。