Forum: Rails-ES Problema para asignar un array a un modelo

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B7de309e2f3436b5b1c0b5c18dad089d?d=identicon&s=25 Carlos Belizón Ibañez (paliyoes)
on 2009-05-05 18:20
He tenido que implementar un algoritmo Round-Robin para crear el
calendario de jornadas de mi aplicación (el algoritmo es correcto), pero
tengo problemas para asignar los resultados a mis modelos, pego aquí el
código:

def create_rounds
  rounds = make_rounds(self.clubs)
  self.rounds = rounds
end

def make_rounds(clubs)
  #If odd insert dummy club
  if clubs.length % 2 == 1
    clubs << :dummy
  end

  rounds_home = []
  rounds_away = []
  num_rounds = clubs.length - 1
  num_matches = clubs.length / 2 - 1

  for i in (1..num_rounds)
    matches_home = []
    matches_away = []
    for j in (0..num_matches)
      matches_home << MatchGeneral.new({
          :local => clubs[j],
          :guest => clubs[num_rounds - j]
        }) #Home match
      matches_away << MatchGeneral.new({
          :local => clubs[num_rounds - j],
          :guest => clubs[j]
        })
    end
    rounds_home << Round.new({
        :round_number => i,
        :match_generals => matches_home
      })
    rounds_away << Round.new({
        :round_number => num_rounds +  i,
        :match_generals => matches_away})
    #rotating the teams
    last = clubs.pop
    clubs.insert(1, last)
  end

  rounds_away.each { |x| rounds_home << x}
  return rounds_home
end

El error que recibo al ejecutar el método create_rounds es este:

undefined method `local_before_type_cast' for #<MatchGeneral:0xb71d0a08>

¿Qué estoy haciendo mal?
B7de309e2f3436b5b1c0b5c18dad089d?d=identicon&s=25 Carlos Belizón Ibañez (paliyoes)
on 2009-05-05 18:54
Sé que el problema está en los match_general ya que si asigno el vector
sin haber rellenado los match_generals funciona perfectamente ¿A qué es
debido esto?
This topic is locked and can not be replied to.