Description
I have a lot of columns in my model.[1] I love Hirb. Now Hirb can't do all of its magic because I have too many columns. But let's face it, I don't want all the columns. I only want certain columns.
I searched a bit in the docs, and tried the following:
Hirb.add_dynamic_view("Wadget", helper: :auto_table) do |o|
{fields: [:id, :name, :token, :important_columns_only]}
end
Though when I called my Wadget.all
, this spec is still not activated as expected. I suspect it's because ActiveRecord::Base
is there.
I realize I'm probably expanding Hirb's scope a little by asking this, but this is something I think that's not unreasonable to provide, especially with the prevalence of AR.
I'd like to add this to the wishlist: a way to indicate to Hirb fields I want (and this touches on #96 with fields one doesn't want). Ideally, this could be done in the config file, but I'll leave to the creator the liberty to say what he would accept.
What I would propose is to either make what I tried work (either by having add_dynamic_view
prepend the list in order of priority, or having Hirb choose a view by the most specific), or being able to specify this in YML config:
views:
fields:
activerecord/base:
exclude:
- updated_at
- created_at
- secret_column
wadget:
only:
- id
- name
- important_stuff
[1]: (It's probably not the ideal structure, but it's an old application with a lot of legacy)