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