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?
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.
Feel free to add me to MSN and/or GTalk as this email.
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
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