if @game.save
flash[:notice] = 'Game was successfully created.'
@home.game_ids = @game@opponent.game_ids = @game
Here are my models
class Game < ActiveRecord::Base
has_and_belongs_to_many :teams
end
class Player < ActiveRecord::Base
belongs_to :team
end
class School < ActiveRecord::Base
has_many :teams
belongs_to :users
def to_param
"#{title.gsub(/[^a-z0-9]+/i, '-')}"
end
end
class Team < ActiveRecord::Base
has_many :players
has_and_belongs_to_many :games
belongs_to :school
belongs_to :user
def to_param
"#{name.gsub(/[^a-z0-9]+/i, '-')}"
end
end
class User < ActiveRecord::Base
has_one :team
has_one :school
end
undefined method `each' for 0:Fixnum
at line
@school = School.find_by_title(params[:school_id].gsub('-', " "))
for team in @school.teams
........
end
Not sure about this one, but it looks like @school.teams is returning a
0, not an array of teams. "each" is called for you when you use a
for/in loop. It is the equivalent of
@school.teams.each { |team| ... }
So "undefined method `each' for 0:Fixnum" means "each" is being called
on the integer 0.
Also I'm getting
undefined method `reject' for #<Game:0x24ca1c4>
From @home.game_ids = @game
@home.game_ids = @game@opponent.game_ids = @game
game_ids= is expecting an array of integers, your are passing it a model
object. You probably just want to insert the game in the existing
association. Try this: