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 ( and her

<%= 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."

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"


@select_winner_loser comes from my results_controller method

  def edit
    @select_winner_loser = []
    @select_winner_loser <<
    @select_winner_loser << @match.bottom
  end and bottom are also commands

class Match < ActiveRecord::Base
    belongs_to  :top, class_name: "Team"
    belongs_to  :bottom, class_name: "Team"
    belongs_to  :result


I don't understand why I would get this because I have the correct objects in my select box, any ideas?



source to share

1 answer


<%= f.collection_select :winner, @select_winner_loser, :id, :name %>



<%= f.collection_select :winner_id, @select_winner_loser, :id, :name %>


and your allowed options. Rails will create an object Team

if it sees a name _id

in a name.



All Articles