我有config/hirb.yml
看起来有点像这样
:output:
BlogEntry:
:options:
:fields:
- id
- title
- url
User:
:options:
:fields:
- id
- first_name
- last_name
在rails控制台中,Hirb将根据hirb.yml规范正确格式化BlogEntry.all
,但不会对User.all
执行此操作。
为什么呢?我该如何解决?
答案 0 :(得分:0)
我在这里找到了答案:
https://github.com/cldwalker/hirb/issues/40
感谢@cldwalker在那里回答完全相同的问题。 (我已经修改了以下引用,因此它与我的问题同步。)
您正在执行
User.all
,但您没有收回用户对象。 你'再 获取作为用户子类的对象。仅支持您的配置 用户对象。让User.all
及其子类接收 配置,添加:ancestor: true
属性::output: User: :ancestor: true :options: :fields: - id - first_name - last_name
我最初没有找到的文档,这对于了解如何使用hirb.yml
非常方便:http://tagaholic.me/hirb/doc/classes/Hirb/Formatter.html