Running Finder as root on OSX – to solve app install issues My passenger config example.
Sep 02

When instantiating a model class this error occurs:

instance = MyModel.new
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.has_key?

This is rectified by placing a super within model class.

def initialize
super
logger.debug("initialize VirtualMta: #{self.class}")
end

3 Responses to “Calling initialize in ActiveRecord model causes nil.has_keys? error.”

  1. Dokumentation von Rails Modellen leicht gemacht Says:

    [...] Calling initialize in ActiveRecord model causes nil.has_keys? error. [...]

  2. Jason Says:

    Why is ’super’ needed? Is this a bug in AR?

  3. hbeaver Says:

    Jason,

    I am not certain as to why ‘initialize’ without super is require. I have not stepped through code yet. I would suspect that some Rails code in ActiveRecord already calls initialize and I am not implementing needed methods or variables in mine. This is in effect like a method override in Java I would think. So when I call empty to pick up parent class, I screw up inheritance.

Leave a Reply