Skip to content


Trouble rendering #31

justinmalone opened this Issue · 5 comments

4 participants


Hi and thanks for ancestry,

Everything is working great in the console but I am getting an undefined method when I try to render this on my index page from within a partial:

"undefined method `name' for nil:NilClass

<%= %>

It does render the parent_id successfully.

<%= category.parent_id %>

In the console I get this, it returns the parent category name:

>> category = Category.find_by_id(2)

=> <Category id: 2, name: "Male", ancestry: "1">


=> "Human"

What am I doing wrong here?


Justin Malone


which version of rails are you using?


This is a bug in rails where conditions are applied when they shouldn't be.

Take a look in your console at the query that is produced when calling ; the conditions that you used to find category are applied along with the condition that selects on category.parent_id.

I reported this issue to the Rails Lighthouse at some point but they told me it would be fixed in Rails 3 when converting to Arel.

Perhaps if you submit the issue again and get some people behind it. I know for a fact that moiristo has the same problem.

If that doesn't work we could start looking into building workarounds into ancestry.


Issue 44 #44 is on similar issues and also proposes a solution. For now you can apply this yourself. I will consider and test adding it to ancestry next time I find time to properly work on it.


Resolved on master in cd268b6 and e552e10

@StefanH StefanH closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.