Wes Gamble
2006-May-10 16:53 UTC
[Rails] What is wrong with this initialize method (code example)?
Here is my class: class Document < ActiveRecord::Base public def initialize puts "Called initialize..." super.initialize end 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 WTF? Wes -- Posted via http://www.ruby-forum.com/.
Vince Puzzella
2006-May-10 16:57 UTC
[Rails] What is wrong with this initialize method (code example)?
I think you just need to call super, not super.initialize On 5/10/06 12:52 PM, "Wes Gamble" <weyus@att.net> wrote:> Here is my class: > > class Document < ActiveRecord::Base > > public > def initialize > puts "Called initialize..." > super.initialize > end > > 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 > > WTF? > > Wes
Vince Puzzella
2006-May-10 17:14 UTC
[Rails] What is wrong with this initialize method (code example)?
>From the "programming ruby" book...Within the body of a method, a call to super acts just like a call to that 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. On 5/10/06 12:52 PM, "Wes Gamble" <weyus@att.net> wrote:> Here is my class: > > class Document < ActiveRecord::Base > > public > def initialize > puts "Called initialize..." > super.initialize > end > > 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 > > WTF? > > Wes
Seemingly Similar Threads
- text_field doesn''t call overridden ActiveRecord getters
- Wrap error_messages_for() call when no instance var present
- Best way to organize non-controller logic???
- rake migrate VERSION=0 doesn''t appear to execute
- ERb question: Embedding <%= %> in helper method calls