我见过多个类似的问题,但没有一个对我有用。
我有一个团队模型:
class Team < ActiveRecord::Base
has_one :p1, :class_name => "Player", :foreign_key => 'player_id', :validate => true
has_one :p2, :class_name => "Player", :foreign_key => 'player_id', :validate => true
end
在我团队的 _form.html.erb 中,我将球员称为
<%= f.collection_select :p1, Player.all, :id, :name %>
但是,在提交表单时,我看到了错误:
Player(#28401456) expected, got String(#14111904)
Application Trace | Framework Trace | Full Trace
app/controllers/teams_controller.rb:47:in `new'
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"GSIcEvROFnvgGWT4HvE2VNqRw4NxU1J8iAw/WhZeRLk=",
"team"=>{"p1"=>"1"},
"commit"=>"Create Team"}
这是行的代码
def create
@team = Team.new(params[:team])
.....
end
请问有什么想法吗?