Record Association Type Mismatch
I have nested results after matches like this
/ matches / 16 / results / 13 / change
If I have the following select box, this shows the correct information (team.name and her team.id)
<%= f.collection_select :winner, @select_winner_loser, :id, :name %>
Now when I try to change my result and pick a winner, I get this:
ActiveRecord :: TeamTypeMismatch Team (# 10504340) expected, received string (# 6163240)
"Hoisted when the object assigned to the association is of the wrong type." http://api.rubyonrails.org/classes/ActiveRecord/AssociationTypeMismatch.html
The winner is the team , result.rb looks like this
class Result < ActiveRecord::Base
has_one :match
belongs_to :winner, class_name: "Team"
belongs_to :loser, class_name: "Team"
end
@select_winner_loser comes from my results_controller method
def edit
@select_winner_loser = []
@select_winner_loser << @match.top
@select_winner_loser << @match.bottom
end
Match.top and bottom are also commands
class Match < ActiveRecord::Base
belongs_to :top, class_name: "Team"
belongs_to :bottom, class_name: "Team"
...
belongs_to :result
end
I don't understand why I would get this because I have the correct objects in my select box, any ideas?
thank
+3
source to share