Validations not working - model mixup?

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:

<form method="post" action="/guesses/create" >

<%= error_messages_for :guess %>

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

<tr>   <td><%= game.home_team.city %></td>   <td><input type="text" name="home_score_<%=game.id%>" size="1" /></td>   <td><input type="text" name="away_score_<%=game.id%>" size="1" /></td>   <td><%= game.away_team.city %></td> </tr> <% end %> </table> <button type="submit" class="button positive">   Save your predictions </button> </form>

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?

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)

I would like to see your controller code before I can say anything more (especially the part where you create the guess) -- Ryan Bigg 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