正如您在下面看到的,我创建了一个哈希,但是我不知道在我的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未联系“,” 1“]的未定义方法'值':数组
你知道我在做什么错吗?
从Rails文档
collection_select(对象,方法,集合,value_method,text_method,options = {},html_options = {})
:value_method和:text_method参数是在集合的每个成员上调用的方法。
您的代码正在尝试调用value
一个不响应该方法的数组。
尝试使用 options_for_select
<%= 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.select :progress, options_for_select(listofprogress, @record.progress_id.to_s), {prompt: true} %>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句