2009/6/19 Martin Hawkins <[email protected]>:
>
> I've got a simple model
>
> class ExtraType < ActiveRecord::Base
>        has_many :match_balls
>        attr_accessor :extra_total
>        def     initialize
>                self.extra_total=0
>        end
> end
>
> When I try
> ex=ExtraType.new, I get
> INTERNAL ERROR!!! You have a nil object when you didn't expect it!
> The error occurred while evaluating nil.has_key?
> /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> base.rb:2633:in `has_attribute?'
>
> I don't think I'm doing anything daft here .. or am I (It's the end of
> a long week after all)

I think you should call super in initialize otherwise it is not doing
the base class initialize.  Also watch out as I think rails does not
always call new to instantiate an object so your initialize may not
get called.  See
http://blog.dalethatcher.com/2008/03/rails-dont-override-initialize-on.html
for example.

Colin


> Ruby 1.8.6 with Rails 2.2.2
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to