# Validations not working - model mixup?

**URL:** <https://www.ruby-forum.com/t/validations-not-working-model-mixup/129281>\
**Category:** Rails\
**Created:** [February 16, 2008, 3:09am UTC](https://www.ruby-forum.com/t/validations-not-working-model-mixup/129281 "2008-02-16T03:09:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [February 16, 2008, 3:09am UTC](https://www.ruby-forum.com/t/validations-not-working-model-mixup/129281/1 "2008-02-16T03:09:54Z")

</div>

Hi there,

I’ve got a list of games, and users can guess the score of each game.  
The guesses are appropriately sent to guesses\_controller.rb, but I can’t  
get any of the validations in guess.rb to work. Here’s what I have in  
the view:

\<%= error\_messages\_for :guess %\>

\<% @games.each do |game| %\>

 \<%= game.home\_team.city %\> \<%= game.away\_team.city %\> \<% end %\> Save your predictions

My model has this:

validates\_numericality\_of :home\_score, :away\_score

Is it because the guesses are called home\_score\_x and away\_score\_x?

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [February 16, 2008, 3:32am UTC](https://www.ruby-forum.com/t/validations-not-working-model-mixup/129281/2 "2008-02-16T03:32:56Z")

</div>

Why aren’t you using the Rails helpers for your text fields?

Can be done as: \<%= text\_field “guess”, “away\_score\_#{game.id}” %\> and  
the  
other one like wise.

## I would like to see your controller code before I can say anything more (especially the part where you create the guess)

Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [February 16, 2008, 4:53am UTC](https://www.ruby-forum.com/t/validations-not-working-model-mixup/129281/3 "2008-02-16T04:53:35Z")

</div>

> ## I would like to see your controller code before I can say anything more (especially the part where you create the guess)
> 
> Ryan B.  
> [http://www.frozenplague.net](http://www.frozenplague.net)  
> Feel free to add me to MSN and/or GTalk as this email.

Here’s the relevant controller code:

guesses\_controller.rb:

def create  
params.keys.select {|k| /home\_score/.match(k)}.each do  
|homescore\_key|  
game\_id = homescore\_key.scan(/\d+/).first.to\_i  
homescore\_val = params[homescore\_key]  
visitingscore\_key = “away\_score\_#{game\_id}”  
visitingscore\_val = params[visitingscore\_key]  
guess = Guess.new(:game\_id =\> game\_id, :home\_score =\>  
homescore\_val, :away\_score =\> visitingscore\_val)  
guess.save  
end  
…  
end
