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 --~--~---------~--~----~------------~-------~--~----~ 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 23 Dec 2007, at 07:43, Thufir wrote:> > Why isn''t this changing the "strength" field in the db? There seems > to > be a disconnect between the row and the object :(Umm, because you''ve commented out creature.save ? Fred> > > > > 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 > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Sun, 23 Dec 2007 10:01:21 +0000, Frederick Cheung wrote:> Umm, because you''ve commented out creature.save ?Pardon, forgot about that. When it''s uncommented it''s almost like the Creature instance has two "strength" attributes: in the db and @strength :( thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ ruby read_creatures.rb Creature Load (0.005061) SELECT * FROM creatures #<Creature:0xb77959fc @attributes={"strength"=>"0", "id"=>"1", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> Creature Update (0.001530) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 1 #<Creature:0xb77959c0 @attributes={"strength"=>"0", "id"=>"2", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> Creature Update (0.000717) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 2 #<Creature:0xb7795998 @attributes={"strength"=>"0", "id"=>"3", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> Creature Update (0.000700) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 3 #<Creature:0xb7795970 @attributes={"strength"=>"0", "id"=>"4", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> Creature Update (0.000720) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 4 #<Creature:0xb7795948 @attributes={"strength"=>"0", "id"=>"5", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> Creature Update (0.000709) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 5 thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ sqlite3 dwemthys.db SQLite version 3.4.1 Enter ".help" for instructions sqlite> sqlite> SELECT * FROM creatures; 1|0|0|0|0 2|0|0|0|0 3|0|0|0|0 4|0|0|0|0 5|0|0|0|0 sqlite> sqlite> .quit thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ 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 23 Dec 2007, at 10:22, Thufir wrote:> > On Sun, 23 Dec 2007 10:01:21 +0000, Frederick Cheung wrote: > > >> Umm, because you''ve commented out creature.save ? > > > > Pardon, forgot about that. When it''s uncommented it''s almost like the > Creature instance has two "strength" attributes: in the db and > @strength :(Is save failing (ie returning false) ? What''s in creatures.rb ? Fred> > > > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ ruby read_creatures.rb > Creature Load (0.005061) SELECT * FROM creatures > #<Creature:0xb77959fc @attributes={"strength"=>"0", "id"=>"1", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> > Creature Update (0.001530) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 1 > #<Creature:0xb77959c0 @attributes={"strength"=>"0", "id"=>"2", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> > Creature Update (0.000717) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 2 > #<Creature:0xb7795998 @attributes={"strength"=>"0", "id"=>"3", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> > Creature Update (0.000700) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 3 > #<Creature:0xb7795970 @attributes={"strength"=>"0", "id"=>"4", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> > Creature Update (0.000720) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 4 > #<Creature:0xb7795948 @attributes={"strength"=>"0", "id"=>"5", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}, @strength=50> > Creature Update (0.000709) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 5 > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ sqlite3 dwemthys.db > SQLite version 3.4.1 > Enter ".help" for instructions > sqlite> > sqlite> SELECT * FROM creatures; > 1|0|0|0|0 > 2|0|0|0|0 > 3|0|0|0|0 > 4|0|0|0|0 > 5|0|0|0|0 > sqlite> > sqlite> .quit > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ > > > > > thanks, > > Thufir > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Sun, 23 Dec 2007 10:43:05 +0000, Frederick Cheung wrote:> Is save failing (ie returning false) ? What''s in creatures.rb ?The save, or update of a row, seems to work. However, it doesn''t seem to update with the expected data. That is, it updates a value of zero, based on the output as I interpret it. Pardon, below is what I meant to post from the get-go: thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ sqlite3 dwemthys.db SQLite version 3.4.1 Enter ".help" for instructions sqlite> SELECT * FROM creatures; 1|0|0|0|0 2|0|0|0|0 3|0|0|0|0 4|0|0|0|0 5|0|0|0|0 sqlite> .quit thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ ruby read_creatures.rb Creature Load (0.006638) SELECT * FROM creatures #<Creature:0xb7773a78 @attributes={"strength"=>"0", "id"=>"1", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> Creature Update (0.001596) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 1 #<Creature:0xb7773a3c @attributes={"strength"=>"0", "id"=>"2", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> Creature Update (0.000731) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 2 #<Creature:0xb7773a14 @attributes={"strength"=>"0", "id"=>"3", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> Creature Update (0.000721) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 3 #<Creature:0xb77739ec @attributes={"strength"=>"0", "id"=>"4", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> Creature Update (0.000736) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 4 #<Creature:0xb77739c4 @attributes={"strength"=>"0", "id"=>"5", "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> Creature Update (0.000727) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 5 thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ sqlite3 dwemthys.db SQLite version 3.4.1 Enter ".help" for instructions sqlite> SELECT * FROM creatures; 1|0|0|0|0 2|0|0|0|0 3|0|0|0|0 4|0|0|0|0 5|0|0|0|0 sqlite> .quit 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| puts creature.inspect creature.save } thufir@arrakis ~/Desktop/dwemthys $ thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ 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 24 Dec 2007, at 01:21, Thufir wrote:> > On Sun, 23 Dec 2007 10:43:05 +0000, Frederick Cheung wrote: > > >> Is save failing (ie returning false) ? What''s in creatures.rb ? > > The save, or update of a row, seems to work. However, it doesn''t > seem to > update with the expected data. That is, it updates a value of zero, > based on the output as I interpret it. >Assuming this is http://dwemthys.googlecode.com/svn/trunk/Creature.rb then your problem is that you''re doing stuff like attr_accessor :life, :strength, :charisma, :weapon This will overwrite the accessors ActiveRecord already provides and stop things working. Also your app will die when you deploy it on a case sensitive file system because you''ve capitalized your file names. Fred> Pardon, below is what I meant to post from the get-go: > > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ sqlite3 dwemthys.db > SQLite version 3.4.1 > Enter ".help" for instructions > sqlite> SELECT * FROM creatures; > 1|0|0|0|0 > 2|0|0|0|0 > 3|0|0|0|0 > 4|0|0|0|0 > 5|0|0|0|0 > sqlite> .quit > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ ruby read_creatures.rb > Creature Load (0.006638) SELECT * FROM creatures > #<Creature:0xb7773a78 @attributes={"strength"=>"0", "id"=>"1", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> > Creature Update (0.001596) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 1 > #<Creature:0xb7773a3c @attributes={"strength"=>"0", "id"=>"2", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> > Creature Update (0.000731) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 2 > #<Creature:0xb7773a14 @attributes={"strength"=>"0", "id"=>"3", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> > Creature Update (0.000721) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 3 > #<Creature:0xb77739ec @attributes={"strength"=>"0", "id"=>"4", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> > Creature Update (0.000736) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 4 > #<Creature:0xb77739c4 @attributes={"strength"=>"0", "id"=>"5", > "charisma"=>"0", "life"=>"0", "weapon"=>"0"}> > Creature Update (0.000727) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 0, "life" = 0 WHERE "id" = 5 > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ sqlite3 dwemthys.db > SQLite version 3.4.1 > Enter ".help" for instructions > sqlite> SELECT * FROM creatures; > 1|0|0|0|0 > 2|0|0|0|0 > 3|0|0|0|0 > 4|0|0|0|0 > 5|0|0|0|0 > sqlite> .quit > 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| > puts creature.inspect > creature.save > } > thufir@arrakis ~/Desktop/dwemthys $ > > > > > > > thanks, > > Thufir > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Mon, 24 Dec 2007 01:27:46 +0000, Frederick Cheung wrote:> Assuming this is http://dwemthys.googlecode.com/svn/trunk/Creature.rb > then your problem is > that you''re doing stuff like > attr_accessor :life, :strength, :charisma, :weapon This will overwrite > the accessors ActiveRecord already provides and stop things working.Yes, your assumption is correct :) I''ve been planning to change the case for the filenames. Instead of attr_accessor, how would I access the a Creature''s attributes in this example? I wasn''t planning on a rails app, but was just poking ActiveRecord. thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Got it :) Thanks, I took out the attr_accessor and just *acted* like it was still there. This is the magic of ActiveRecord? Kinda weird, but it worked: thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ ruby read_creatures.rb Creature Load (0.017017) SELECT * FROM creatures #<Creature:0xb77b0c98 @attributes={"strength"=>"0", "id"=>"1", "charisma"=>"0", "life"=>"0", "weapon"=>1000}> Creature Update (0.003406) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 1 #<Creature:0xb77b0c5c @attributes={"strength"=>"0", "id"=>"2", "charisma"=>"0", "life"=>"0", "weapon"=>1000}> Creature Update (0.000733) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 2 #<Creature:0xb77b0c34 @attributes={"strength"=>"0", "id"=>"3", "charisma"=>"0", "life"=>"0", "weapon"=>1000}> Creature Update (0.000757) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 3 #<Creature:0xb77b0c0c @attributes={"strength"=>"0", "id"=>"4", "charisma"=>"0", "life"=>"0", "weapon"=>1000}> Creature Update (0.000733) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 4 #<Creature:0xb77b0be4 @attributes={"strength"=>"0", "id"=>"5", "charisma"=>"0", "life"=>"0", "weapon"=>1000}> Creature Update (0.000718) UPDATE creatures SET "charisma" = 0, "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 5 thufir@arrakis ~/Desktop/dwemthys $ thufir@arrakis ~/Desktop/dwemthys $ sqlite3 dwemthys.db SQLite version 3.4.1 Enter ".help" for instructions sqlite> SELECT * FROM creatures; 1|0|0|0|1000 2|0|0|0|1000 3|0|0|0|1000 4|0|0|0|1000 5|0|0|0|1000 sqlite> .quit 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.weapon = 1000 puts creature.inspect creature.save } thufir@arrakis ~/Desktop/dwemthys $ -Thufir --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
yes, that''s the magic of ActiveRecord. On Dec 24, 2007 3:51 PM, Thufir <hawat.thufir-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Got it :) > > Thanks, I took out the attr_accessor and just *acted* like it was > still there. This is the magic of ActiveRecord? Kinda weird, but it > worked: > > > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ ruby read_creatures.rb > Creature Load (0.017017) SELECT * FROM creatures > #<Creature:0xb77b0c98 @attributes={"strength"=>"0", "id"=>"1", > "charisma"=>"0", "life"=>"0", "weapon"=>1000}> > Creature Update (0.003406) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 1 > #<Creature:0xb77b0c5c @attributes={"strength"=>"0", "id"=>"2", > "charisma"=>"0", "life"=>"0", "weapon"=>1000}> > Creature Update (0.000733) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 2 > #<Creature:0xb77b0c34 @attributes={"strength"=>"0", "id"=>"3", > "charisma"=>"0", "life"=>"0", "weapon"=>1000}> > Creature Update (0.000757) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 3 > #<Creature:0xb77b0c0c @attributes={"strength"=>"0", "id"=>"4", > "charisma"=>"0", "life"=>"0", "weapon"=>1000}> > Creature Update (0.000733) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 4 > #<Creature:0xb77b0be4 @attributes={"strength"=>"0", "id"=>"5", > "charisma"=>"0", "life"=>"0", "weapon"=>1000}> > Creature Update (0.000718) UPDATE creatures SET "charisma" = 0, > "strength" = 0, "weapon" = 1000, "life" = 0 WHERE "id" = 5 > thufir@arrakis ~/Desktop/dwemthys $ > thufir@arrakis ~/Desktop/dwemthys $ sqlite3 dwemthys.db > SQLite version 3.4.1 > Enter ".help" for instructions > sqlite> SELECT * FROM creatures; > 1|0|0|0|1000 > 2|0|0|0|1000 > 3|0|0|0|1000 > 4|0|0|0|1000 > 5|0|0|0|1000 > sqlite> .quit > 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.weapon = 1000 > puts creature.inspect > creature.save > } > thufir@arrakis ~/Desktop/dwemthys $ > > > > -Thufir > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
to create it from scratch: Creature.new({:strength => 50}) To update a single attribute: creature = Creature.find(id) creature.update_attribute("strengh",50) To update a whole heap of attributes: creature = Creature.find(id) create.update_attributes({:strength => 50, :life => 20}) On Dec 24, 2007 3:25 PM, Thufir <hawat.thufir-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Mon, 24 Dec 2007 01:27:46 +0000, Frederick Cheung wrote: > > > Assuming this is http://dwemthys.googlecode.com/svn/trunk/Creature.rb > > then your problem is > > that you''re doing stuff like > > attr_accessor :life, :strength, :charisma, :weapon This will overwrite > > the accessors ActiveRecord already provides and stop things working. > > Yes, your assumption is correct :) > > I''ve been planning to change the case for the filenames. > > Instead of attr_accessor, how would I access the a Creature''s attributes > in this example? I wasn''t planning on a rails app, but was just poking > ActiveRecord. > > > thanks, > > Thufir > > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 Mon, 24 Dec 2007 16:46:37 +1030, Ryan Bigg wrote:> creature = Creature.find(id) > creature.update_attribute("strengh",50) > > To update a whole heap of attributes: > > creature = Creature.find(id) > create.update_attributes({:strength => 50, :life => 20})Thanks. These commands are similar, if not identical, to what''s available from the script/console interface. -Thufir --~--~---------~--~----~------------~-------~--~----~ 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 24 Dec 2007, at 04:55, Thufir wrote:> > On Mon, 24 Dec 2007 01:27:46 +0000, Frederick Cheung wrote: > >> Assuming this is http://dwemthys.googlecode.com/svn/trunk/Creature.rb >> then your problem is >> that you''re doing stuff like >> attr_accessor :life, :strength, :charisma, :weapon This will >> overwrite >> the accessors ActiveRecord already provides and stop things working. > > Yes, your assumption is correct :) > > I''ve been planning to change the case for the filenames. > > Instead of attr_accessor, how would I access the a Creature''s > attributes > in this example? I wasn''t planning on a rails app, but was just > poking > ActiveRecord.You don''t need attr_accessor because AR already provides accessors for you. Fred> > > > thanks, > > Thufir > > > --~--~---------~--~----~------------~-------~--~----~ > 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--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The script/console interface is exactly the same environment you''re given in the application, minus there actually being a real request generating the code (although that can be faked too!) Consider this my last post for the next two days. Merry Christmas to everyone. On Dec 24, 2007 9:42 PM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 24 Dec 2007, at 04:55, Thufir wrote: > > > > > On Mon, 24 Dec 2007 01:27:46 +0000, Frederick Cheung wrote: > > > >> Assuming this is http://dwemthys.googlecode.com/svn/trunk/Creature.rb > >> then your problem is > >> that you''re doing stuff like > >> attr_accessor :life, :strength, :charisma, :weapon This will > >> overwrite > >> the accessors ActiveRecord already provides and stop things working. > > > > Yes, your assumption is correct :) > > > > I''ve been planning to change the case for the filenames. > > > > Instead of attr_accessor, how would I access the a Creature''s > > attributes > > in this example? I wasn''t planning on a rails app, but was just > > poking > > ActiveRecord. > > You don''t need attr_accessor because AR already provides accessors > for you. > > Fred > > > > > > > > thanks, > > > > Thufir > > > > > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---