class Round < ActiveRecord::Base
  attr_accessible :charity, :closed, :expire_time, :failed, :max_amount, :secret_token, :url, :winning_address1, :winning_address2

  has_many :donations

  after_initialize do |round|
    self.url = SecureRandom.hex(3)
    self.expire_time = Time.now + 1.hours
    self.save
  end
end

class Round < ActiveRecord::Base
  attr_accessible :charity, :closed, :expire_time, :failed, :max_amount, :secret_token, :url, :winning_address1, :winning_address2

  has_many :donations

  after_initialize do |round|
    if self.url.nil?
      self.url = SecureRandom.hex(3)
    end
    if self.expire_time.nil?
      self.expire_time = Time.now + 1.hours
    end
    self.save
  end
end

Update Round attributes in after_initialize only if nil
Update Round attributes in after_initialize only if nil
