正如您在下面看到的,我创建了一个哈希,但我不知道在我的 collection_select 标记中引用该哈希。所以我已经成功地做到了,但是我的哈希是配置文件对象的集合,当我尝试使用键值对的集合来做它似乎不起作用时,我将首先向您展示正确工作的代码然后我'将向您展示无效的代码。
这给了我零错误:
<% listoflos = [] %>
<% @profiles.each do |profile| %>
<% listoflos.push(profile) if profile.title == "loan officer" %>
<% end %>
<%= f.collection_select :loanofficer_id, listoflos, :user_id, :firstname, {prompt: true} %>
这给了我错误:
<%= f.label "Progress" %> 
<% listofprogress = [["1 Not contacted", "1"],["2 Interested", "2"],["3 App Taken", "3"],["4 Priced", "4"],["5 Disclosure Signed", "5"],["6 No Appraisal Needed", "6"],["7 Appraisal Ordered", "7"],["8 Appraisal Recieved", "8"],["9 In Underwriting", "9"],["10 Closing Scheduled", "10"],["11 Closed", "11"],["12 Dead", "12"],["Unknown", "unknown"]] %>
<%= f.collection_select :progress, listofprogress, :id, :value, {prompt: true} %>
我收到一个错误:
Records#edit 中的 NoMethodError 显示 c:/Sites/TeamCRM/app/views/records/_eform.html.erb 其中第 52 行引发:
["1 Not contacted", "1"]:Array 的未定义方法“值”
你知道我做错了什么吗?