Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying ActiveRecord descendents custom views #97

Open
joallard opened this issue Feb 3, 2016 · 3 comments
Open

Specifying ActiveRecord descendents custom views #97

joallard opened this issue Feb 3, 2016 · 3 comments

Comments

@joallard
Copy link

joallard commented Feb 3, 2016

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)

@cldwalker
Copy link
Owner

Thanks for reporting your issue! This is one of my 13 active issues. Use that link to check how soon your issue will be answered. Don't forget to check your issue against this project's CONTRIBUTING.md. Cheers.

@thams
Copy link

thams commented Oct 25, 2016

any chance this gets done? I'd really like this feature.

@joallard
Copy link
Author

I hear pull requests are fun ;o)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants