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

hirb.yml fields spec ignored when class name is "Task" #40

Closed
pdobb opened this issue Feb 28, 2011 · 4 comments
Closed

hirb.yml fields spec ignored when class name is "Task" #40

pdobb opened this issue Feb 28, 2011 · 4 comments

Comments

@pdobb
Copy link

pdobb commented Feb 28, 2011

This seems odd... so please let me know if you'd like me to try anything further to help debug. I've set up several custom field sets for several classes and they all work great, except for the one that I've defined for my Task class.

A very simplified example from my hirb.yml file:

:output:
  Task:
    :options:
      :fields:
        - id

Now I load a fresh Rails console and do:

Task.all

The output is a table that shows every column in my tasks table, instead of just the id column.

Now... my Task class is a superclass for a few other Task types (e.g. SubscribeTask). Let's try this on the console:

SubscribeTask.all

Nope. Same table that's showing all columns. But that's OK -- I expected that. I'm just saying to lead into my next discovery.

Recently, I tried changing my hirb.yml to use one of the subclass names like this:

:output:
  SubscribeTask:
    :options:
      :fields:
        - id

Now I load a fresh Rails console and do:

SubscribeTask.all

The output is a table that shows just the id column as I was expecting.

So what is it about the class name "Task" that is causing hirb to not render the table with my configured columns?

Thanks so much for your help!

P.S. I've observed this in Ruby 1.8.7, Rails 3.0.5 (also Rails 2.3.9)

@cldwalker
Copy link
Owner

Seems odd but there's not much I can do without your code or specific errors. Have you tried a vanilla rails app with just those two models copied over? If so, is it up on github?

If you want to make sure hirb works with Task, you can always:

 puts Hirb::Helpers::AutoTable.render(Task.all, :fields => [:id])

@pdobb
Copy link
Author

pdobb commented Mar 3, 2011

Yes, now I have and now I do. Here you go: https://github.com/pdobb/hirb_test

Thanks again!

@cldwalker
Copy link
Owner

Ok. Now I understand the issue. You're doing Task.all but you're not getting back task objects. You're getting back SubscribeTask objects. Your configuration only supported Task objects. To have Task all and its subclasses receive the configuration, add the :ancestor option:

:output:
  Task:
    :ancestor: true
    :options:
      :fields:
       - id

@pdobb
Copy link
Author

pdobb commented Mar 4, 2011

Brilliant! That's exactly what I needed and makes sense even. Thanks very much!

This issue was closed.
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

2 participants