Something is getting lost here.
def create
@home = Team.find_by_user_id(current_user.id)
for player in @home.players
player.update_attribute(:game_id, @game.id)
end
end
def show
@players = Player.find_all_by_game_id(params[:id])
end
view
<%= @players.size %> # mistakenly equals zero
Played with the console and everything should be working fine...
You don't seem to be setting @game in your create method.
It'd help if you told us what your error was.
Julian.
Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out TODAY!
http://sensei.zenunit.com/
def create
@game = Game.new(params[:game])
@game.opponent = params[:team][:name]
@home = Team.find_by_user_id(current_user.id)
@opponent = Team.find_by_name(params[:team][:name])
for player in @home.players
player.update_attribute(:game_id, @game.id)
end
if @game.save
flash[:notice] = 'Game was successfully created.'
redirect_to
edit_school_team_game_url(School.find_by_user_id(current_user.id),
@home, @game)
else
render :action => "new"
end
end
is my whole create method
the error is that the game_id is never actually changed for any of the
players. it remains nil
def edit
@game = Game.find(params[:id])
@players = Player.find_all_by_game_id(params[:id])
end
Am I not describing my problem correctly?
i'm absolutely perplexed...
Player Update (0.000416) UPDATE players SET "created_at" =
'2008-04-07 12:35:45', "school_id" = 2, "team_id" = 2, "first" = 'w',
"updated_at" = '2008-04-07 12:43:38', "game_id" = NULL, "last" = 'o'
WHERE "id" = 4
Why is it not setting game_id???
i'm absolutely perplexed...
Player Update (0.000416) UPDATE players SET "created_at" =
'2008-04-07 12:35:45', "school_id" = 2, "team_id" = 2, "first" = 'w',
"updated_at" = '2008-04-07 12:43:38', "game_id" = NULL, "last" = 'o'
WHERE "id" = 4
Why is it not setting game_id???
The game hasn't been saved and so it doesn't have an id.
Fred
You're a genius thank you for finding my silly mistake.