提问人:user3494179 提问时间:4/3/2023 更新时间:4/3/2023 访问量:21
Rails rabl 全局别名?
Rails rabl global alias?
问:
我在rails(单表继承)中有以下模型:
class Foo < ActiveRecord::Base
end
Class Bar < Foo
end
还有像这样的乌合之众:
@foo
attributes ...
当 I 返回 Bar 的实例时。这导致我的 rabl 返回一个 json,如下所示:@foo = Foo.find(<id of an record of type Bar>)
{
"bar": {}
}
在我的前端,我使用 json 获取对象。但这行不通,因为现在它又回来了。response.foo
response.bar
我不想在我的前端考虑所有可能的不同子类。我的前端不关心子类。我希望所有子类都返回到我的前端。Foo
Foo
在 rabl 中,我可以简单地分配一个别名,如下所示: 但这需要我手动对我所有现有的 rabl 文件进行此更改。有没有办法为的所有子类配置默认别名“Foo”?@foo => :bar
Foo
答: 暂无答案
评论