我已经看到类似这样的多个问题,但都没有为我工作。栏杆对象预期得到字符串
我有一个团队模式:
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
任何想法的代码吗?
感谢这 - 非常误导性的错误信息 - 应该告诉我们列名不匹配,并且将是一个20秒的修复,而不是一个小时 – JosephK 2015-11-17 19:13:03
对此不能感谢。这也适用于铁轨5的强烈参数。 – 2017-04-22 16:50:09