Daniel Völkerts
2009-Jan-09 21:26 UTC
ActiveRecord: Can''t store a class derived from AR::Base
Hi, try to use ActiveRecord for my little standalone application, without the rails environment. Here is my first try 8<-------------------------------------------------- # Main if __FILE__ == $0 then ActiveRecord::Base.establish_connection( :adapter => ''mysql'', :host => @config[:sql][:hostname], :database => @config[:sql][:database], :username => @config[:sql][:username], :password => @config[:sql][:password] ) puts ''Erzeuge ein paar Knoten und speicher diese in der DB: '' 80.times do |i| aNode = Node.new("node_#{i}",1) print ''.'' aNode.save! end end 8<-------------------------------------------------- @config is well initialized, the ActiveRecord connects to my DB as you''ll expected. But the call aNode.save! fails with this error: Erzeuge ein paar Knoten und speicher diese in der DB: .c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:164:in `rollback_active_record_state!'': undefined method `delete'' for nil:NilClass (NoMethodError) from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:150:in `save!'' from main.rb:35 from main.rb:32:in `times'' from main.rb:32 Mmm, but I have looked in transactions.rb at line 150 and 164, looks fine for me. My AR gems are D:\ramantics>gem list --local *** LOCAL GEMS *** actionmailer (2.2.2) actionpack (2.2.2) activerecord (2.2.2) activeresource (2.2.2) activesupport (2.2.2) fxri (0.3.7, 0.3.6) fxruby (1.6.17, 1.6.6) hpricot (0.6.164, 0.4) log4r (1.0.5) mysql (2.7.3) ptools (1.1.6) rails (2.2.2) rake (0.8.3, 0.7.2) rubygems-update (1.3.1) sources (0.0.1) test-unit (2.0.2) win32-api (1.2.2) win32-clipboard (0.4.4, 0.4.1) win32-dir (0.3.2, 0.3.1) win32-eventlog (0.5.0, 0.4.3) win32-file (0.6.0, 0.5.3) win32-file-stat (1.3.2, 1.2.3) win32-process (0.6.0, 0.5.1) win32-sapi (0.1.4, 0.1.3) win32-sound (0.4.1, 0.4.0) windows-api (0.2.4) windows-pr (0.9.8, 0.6.2) Has anyone an idea where I made the mistake? Thanks a lot. g, Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Jan-10 19:42 UTC
Re: ActiveRecord: Can''t store a class derived from AR::Base
On Jan 9, 9:26 pm, Daniel Völkerts <d...-XM+ZIY/z7BcOIzVOb1FTxg@public.gmane.org> wrote:> Has anyone an idea where I made the mistake? Thanks a lot.Have you override initialize in you Node class ? Fred> > g, > > Daniel--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Völkerts
2009-Jan-11 11:33 UTC
Re: ActiveRecord: Can''t store a class derived from AR::Base
Frederick Cheung schrieb:> Have you override initialize in you Node class ?Hi Fred, aaah yes. I already found the problem. As you mentioned, I overwrote initialize in my Node class which inherits AR::Base. Damn I didn''t know that this isn''t allowed :( Fixed failures lead to better code *g* Thanks for your response. Daniel -- “Das ich erkenne, was die Welt im Innersten zusammenhält” (Faust I) --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Jan-11 14:21 UTC
Re: ActiveRecord: Can''t store a class derived from AR::Base
On 11 Jan 2009, at 11:33, Daniel Völkerts wrote:> > Frederick Cheung schrieb: > >> Have you override initialize in you Node class ? > > Hi Fred, > > > aaah yes. I already found the problem. As you mentioned, I overwrote > initialize in my Node class which inherits AR::Base. > > Damn I didn''t know that this isn''t allowed :( Fixed failures lead to > better code *g* >You can override initialize, but you just need to ensure you call the superclass implementation properly. Fred> Thanks for your response. > > Daniel > > -- > “Das ich erkenne, was die Welt im Innersten zusammenhält” (Faust I) > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Völkerts
2009-Jan-11 20:05 UTC
Re: ActiveRecord: Can''t store a class derived from AR::Base
Frederick Cheung schrieb:> You can override initialize, but you just need to ensure you call the > superclass implementation properly.Oh, thanks for this additional information, I see I''ve to read the docs ,) g, Daniel -- “Das ich erkenne, was die Welt im Innersten zusammenhält” (Faust I) --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---