Hey guys I’m having a little trouble what I think should be a pretty
simple relationship between tables.
Player.rating is a f-key to Rating.id, both fields are integers
When I try to add a new player I get this error message
ActiveRecord::AssociationTypeMismatch in PlayersController#create
Rating(#38968656) expected, got String(#19165136)
In my form I have this for the rating dropdown
f.select :rating, options_for_select(Rating.all.map { |r| [r.level,
r.id] })
In my models I have
#player
has_one :rating
#rating
belongs_to :player, :foreign_key => “id”
You’ve got it backwards. foreign_key gives the name of the key on the
other table, so in this case, it would be ‘rating’, not ‘id’. But why
not follow the Rails conventions, call the column Player.rating_id , and
drop the foreign key clause?