Two models, a game, and a player.  The game should start as soon as
there are enough players in the game
#####################################################

class Game < ActiveRecord::Base
  has_many :players

  should_start
    return players.count >= number_of_players #number_of_players is
defined in the database
  end

  def start
    started = true  #started is a variable defined in the database
    save
  end
end

class Player < ActiveRecord::Base
  belongs_to :game
  after_save :check_game_start

  def check_game_start
    game.start if game.should_start?
  end
end

#########################################
The problem with this code, is that the record has not yet been saved
to the database by the time after_save has been called.  Looking
around the forum, it appears that there is no after_commit callback.
What is the correct way to do this?  Should I change the game to start
at some other point, should I change the RoR code to add the callback
myself, or should I add some hack to make it guess what the new state
of the database is to get it to start?

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to