我已經看到類似這樣的多個問題,但都沒有爲我工作。欄杆對象預期得到字符串
我有一個團隊模式:
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