相关疑难解决方法(0)

国家预期,得到字符串错误

我有2个模型"国家"和"联盟",国家有很多联赛和联盟属于国家.添加联盟时,我有一个包含国家/地区的列表框,在提交表单时,会发送实际国家/地区:

{"commit"=>"Create League",
 "authenticity_token"=>"wuAuj5vowkk2R56TuFkWE8J3x3vue5RbnNPcbpjuG3Q=",
 "utf8"=>"✓",
 "league"=>{"league_short"=>"CL",
 "country"=>"England",
 "level"=>"2",
 "league"=>"The Championship"}}
Run Code Online (Sandbox Code Playgroud)

但后来我收到此错误消息:

Country expected, got String
Run Code Online (Sandbox Code Playgroud)

在Country模型中,我将country_id(整数)和country(字符串)作为字段,在League模型中,我将country作为字符串字段.在联盟控制器中,我有这个打赌下拉:@countries = Country.dropdown_list.在联盟/新视图中,我有这个选择字段:<%= f.select :country, @countries %>.出了什么问题?

ruby-on-rails

6
推荐指数
3
解决办法
2万
查看次数

标签 统计

ruby-on-rails ×1