Why isn’t this changing the “strength” field in the db? There seems to
be a disconnect between the row and the object
thufir@arrakis ~/Desktop/dwemthys $
thufir@arrakis ~/Desktop/dwemthys $ ruby read_creatures.rb
Creature Load (0.005096) SELECT * FROM creatures
#<Creature:0xb7747b58 @attributes={“strength”=>“0”, “id”=>“1”,
“charisma”=>“0”, “life”=>“0”, “weapon”=>“0”}, @strength=50>
#<Creature:0xb7747b1c @attributes={“strength”=>“0”, “id”=>“2”,
“charisma”=>“0”, “life”=>“0”, “weapon”=>“0”}, @strength=50>
#<Creature:0xb7747af4 @attributes={“strength”=>“0”, “id”=>“3”,
“charisma”=>“0”, “life”=>“0”, “weapon”=>“0”}, @strength=50>
#<Creature:0xb7747acc @attributes={“strength”=>“0”, “id”=>“4”,
“charisma”=>“0”, “life”=>“0”, “weapon”=>“0”}, @strength=50>
#<Creature:0xb7747aa4 @attributes={“strength”=>“0”, “id”=>“5”,
“charisma”=>“0”, “life”=>“0”, “weapon”=>“0”}, @strength=50>
thufir@arrakis ~/Desktop/dwemthys $
thufir@arrakis ~/Desktop/dwemthys $ cat read_creatures.rb
require ‘fileutils’
require ‘active_record’
require ‘Creature’
require ‘Dragon’
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = true
ActiveRecord::Base.establish_connection(
:adapter => “sqlite3”,
:dbfile => “dwemthys.db”
)
Creature.find(:all).each { |creature|
creature.strength = 50
puts creature.inspect
creature.save
}
thufir@arrakis ~/Desktop/dwemthys $
thufir@arrakis ~/Desktop/dwemthys $
thanks,
Thufir