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:in `initialize''
from (irb):2:in `new''
from (irb):2
Someone knows why?
thanks
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 16 Jul 2008, at 14:33, Tarscher wrote:> > 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:in `initialize'' > from (irb):2:in `new'' > from (irb):2 > > Someone knows why?You haven''t called the superclass initialize Fred> > > thanks > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 16, 2008, at 9:53 AM, Frederick Cheung wrote:> On 16 Jul 2008, at 14:33, Tarscher wrote: >> 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:in `initialize'' >> from (irb):2:in `new'' >> from (irb):2 >> >> Someone knows why? > You haven''t called the superclass initialize > > Fred >> >> thanksIs this something for which a before_create callback would work? -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I always use this syntax:
def initialize(params = nil)
super(nil)
self.whatever ||= "blarg"
end
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---