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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Why aren''t you using the Rails helpers for your text fields? <input type="text" name="away_score_<%=game.id%>" size="1" /> 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 Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---