Constructor in model

Hi all,

I have an activation model that when constructed should set the key
(column in the activations table) to test.

class Activation < ActiveRecord::Base
belongs_to :user

def initialize
this.key = “test”
end
end

When i do ac = Activation.new I gget
NoMethodError: You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?
from C:/rails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/attribute_methods.rb:202:in method_missing' from C:/Documents and Settings/AIR14607/My Documents/prive/rails/ TeamGeist/app/models/activation.rb:5:ininitialize’
from (irb):2:in `new’
from (irb):2

Someone knows why?

thanks

On 16 Jul 2008, at 14:33, Tarscher wrote:

this.key = “test”
TeamGeist/app/models/activation.rb:5:in initialize' from (irb):2:innew’
from (irb):2

Someone knows why?
You haven’t called the superclass initialize

Fred

On Jul 16, 2008, at 9:53 AM, Frederick C. wrote:

this.key = “test”
TeamGeist/app/models/activation.rb:5:in initialize' from (irb):2:in new’
from (irb):2

Someone knows why?
You haven’t called the superclass initialize

Fred

thanks

Is this something for which a before_create callback would work?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

I always use this syntax:

def initialize(params = nil)
super(nil)
self.whatever ||= “blarg”
end