Forum: Ruby on Rails What is wrong with this initialize method (code example)?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Wes G. (Guest)
on 2006-05-10 20:52
Here is my class:

class Document < ActiveRecord::Base

  def initialize
    puts "Called initialize..."

This generates the following error:

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occured while evaluating nil.initialize


Vince P. (Guest)
on 2006-05-10 20:58
(Received via mailing list)
I think you just need to call super, not super.initialize
Vince P. (Guest)
on 2006-05-10 21:17
(Received via mailing list)
>From the "programming ruby" book...

Within the body of a method, a call to super acts just like a call to
original method, except that the search for a method starts in the
superclass of the object that was found to have the original method.

Explains why you are getting the nil.initialize error.  'super' is like
calling initialize, which returns nil.
This topic is locked and can not be replied to.