If statement not working as intended?

for some reason i can not get toss_won and toss_won to be saved
properly.
during testing i replaced toss_won = 34, toss_lost = 45 and
everything worked but i have also tested the values generated
by: toss_lost = check_teams[0][1], tested in console as well.

@teams is an array of the two teams ie: [ [‘rangers’ 23] [‘red sox’
45] ]

if someone has an easier way or how to fix this let me know.

what is being saved constantly to game.bat_1 and game.

@game = Game.new(params[:game])

# select which teams batted and bowled first and seccond

check_teams = @teams
toss_won = params[:toss_won]

#delete the team that won the toss
check_teams.delete_if { |a| [*a].include?(toss_won) }

#check_teams is now an array with 1 element consisting of name and
id
#toss_lost extracts the team id which is to be saved.
toss_lost = check_teams[0][1]

check to see if the team that won the toss elected to ‘Bat’ or

‘Pitch’
if params[:elected] == “Bat”
@game.bat_1 = toss_won
@game.bat_2 = toss_lost
@game.field_1 = toss_lost
@game.field_2 = toss_won
else
@game.bat_1 = toss_lost
@game.bat_2 = toss_won
@game.field_1 = toss_won
@game.field_2 = toss_lost
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs