# If statement not working as intended?

**URL:** <https://www.ruby-forum.com/t/if-statement-not-working-as-intended/135738>\
**Category:** Rails\
**Created:** [April 24, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/if-statement-not-working-as-intended/135738 "2008-04-24T15:58:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rushnosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rushnosh](https://www.ruby-forum.com/u/rushnosh)\
**Post date:** [April 24, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/if-statement-not-working-as-intended/135738/1 "2008-04-24T15:58:16Z")

</div>

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
