ruby-on-rails – rails对象期望得到字符串
发布时间:2020-12-17 03:05:01 所属栏目:百科 来源:网络整理
导读:我见过类似的多个问题,但没有一个对我有用. 我有一个团队模型: class Team ActiveRecord::Base has_one :p1,:class_name = "Player",:foreign_key = 'player_id',:validate = true has_one :p2,:validate = trueend 在我的团队的_form.html.erb中,我指的是
我见过类似的多个问题,但没有一个对我有用.
我有一个团队模型: class Team < ActiveRecord::Base has_one :p1,:class_name => "Player",:foreign_key => 'player_id',:validate => true has_one :p2,: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 有什么想法吗? 解决方法
最后,这工作:
<%= f.collection_select :p1_id,:name %> 这是魔术: def create @team = Team.new(params[:team]) ..... end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |