我试图在轨道上的红宝石上做一个下拉选择框,但遇到下面的错误
错误
NoMethodError - undefined method `typename' for {"typename"=>"dasds"}:Hash:
视图
= f.input :visitortype, collection: @visitor_types_collection, label_method: 'typename', include_blank: false, required: true, class:"form-control"
控制器(这个>的错误)
@visitor_types_collection = [{"typename" => "dasds"}]
对于你的信息,我实际上是想把它放进去(上面的例子只是为了弄清楚它是如何完成的):
{"visitor_types" => [{"typename" => "Friend",
"require_mgmt_approval" => "false"},
{"typename" => "Delivery",
"require_mgmt_approval" => "true"},
{"typename" => "Contractor",
"require_mgmt_approval" => "true"}
]}
答案 0 :(得分:0)
你可以尝试使用这样的键值格式:
在控制器中:
@visitor_types_collection = [['Option1','Value1'],['Option2','Value2']]
= f.select :visitortype, collection: @visitor_types_collection, label_method: 'typename', include_blank: false, required: true, class:"form-control"