Why does hirb.yml ignore User?

40 views Asked by At

I have a config/hirb.yml which looks a bit like this

:output:
  BlogEntry:
    :options:
      :fields:
        - id
        - title
        - url
  User:
    :options:
      :fields:
        - id
        - first_name
        - last_name

In the rails console, Hirb will properly format BlogEntry.all according to the hirb.yml specification, but will not do that for User.all.

Why? And how do I fix it?

1

There are 1 answers

0
Magne On

I found the answer here:

https://github.com/cldwalker/hirb/issues/40

Thanks to @cldwalker for answering the exact same question there. (I've modified the below quote so it syncs to my question.)

You're doing User.all but you're not getting back user objects. You're getting back objects which are some subclass of user. Your configuration only supported User objects. To have User.all and its subclasses receive the configuration, add the :ancestor: true property:

:output:
  User:
    :ancestor: true
    :options:
      :fields:
       - id
       - first_name
       - last_name

The documentation that I didn't find at first, which is handy for knowing how to use hirb.yml: http://tagaholic.me/hirb/doc/classes/Hirb/Formatter.html