Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Trouble rendering parent.name #31

Closed
justinmalone opened this Issue · 5 comments

4 participants

Justin Malone Reinier de Lange Stefan Kroes StefanH
Justin Malone

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

<%= category.parent.name %>

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">

>> category.parent.name

=> "Human"

What am I doing wrong here?

Best,

Justin Malone

Reinier de Lange

which version of rails are you using?

Stefan Kroes
Owner

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 category.parent.name ; 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.

Stefan Kroes
Owner

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.

StefanH
Collaborator

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.