can't dup NilClass - Error
Asked Answered
W

2

6

I am stuck in this error for quite sometime now and have hit a dead end.

I get this totally unhelpful error

can't dup NilClass

This is the situation.

I have one class which is in a relationship with another. Say

 class Parent
 end

 class Child < Parent
    unloadable
     :has_many :parents, :foreign_key => "child"
 end

The error does not occur the first time it is accessed. It occurs the second time the child is accessed.

What is exactly causing this error and is there a solution?

I referred the following link but it doesn't help

Update

I found this

But it suggests the same again. But i do have a module in my lib. It Has nothing to do with the model though.

Wadley answered 19/7, 2010 at 6:17 Comment(0)
T
3

Why are you marking the Child as unloadable? Is there a good reason for this? if not, I'd remove.

Rails API says "Unloadable constants are removed each time dependencies are cleared."

Does the error happen when you change it to:

class Child < Parent
  has_many :parents, :foreign_key => "child"
end

And, I may be overstepping, but this seems more standard:

class Child
  belongs_to :parent
end

class Parent
  has_many :children, :dependent=>:destroy
end
Treasonous answered 19/7, 2010 at 12:52 Comment(2)
but rails.rubyonrails.org/classes/ActiveRecord/Associations/… says not to use :destroy when using :has_many.?Wadley
I believe it means don't have "belongs_to :parent, :dependent=>:destroy" -- in that case, if a parent has 4 children, and you destroy a child, then the child and the parent would be destroyed, but the other 3 child remain orphans.Treasonous
A
0

this is an error from the underground infrastructure. it may caused by very basic grammar error or so .

so I suggest you make sure all the config files are present(especially the config folder, those yaml files )

In my case, I solved this issue by adding the config/application.yml (which is a config file)

Aldred answered 18/3, 2019 at 12:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.