Rails collection_select如何正确引用哈希?

合法堆栈

正如您在下面看到的,我创建了一个哈希,但是我不知道在我的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" %>&nbsp
  <% 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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何从 collection_select rails 处理数组

来自分类Dev

如何在Rails 4中禁用collection_select

来自分类Dev

Rails 4动态Collection_Select

来自分类Dev

Rails collection_select传递ID

来自分类Dev

Rails处理collection_select的列表

来自分类Dev

rails 4 collection_select多个嵌套属性无法正确保存

来自分类Dev

Rails collection_select与f.collection_select

来自分类Dev

Rails 4 +枚举:如何对collection_select中的值进行大写?

来自分类Dev

如何在Rails的collection_select字段中放置“添加新”链接

来自分类Dev

在Rails中使用collection_select时如何显示相关模型的属性

来自分类Dev

Rails:如何在collection_select中添加自定义数据属性

来自分类Dev

如何在Rails中通过JavaScript函数添加collection_select和text_area?

来自分类Dev

如何在表单collection_select rails中将多个id作为数组传递?

来自分类Dev

Ruby on Rails:如何更改collection_select下拉列表上的Foriegn Key值?

来自分类Dev

在Rails中使用collection_select时如何显示相关模型的属性

来自分类Dev

如何在仅显示具有特定属性的选项的rails中进行collection_select

来自分类Dev

如何在Rails中使用嵌套属性编写collection_select

来自分类Dev

Rails 4:如何通过AJAX基于另一个collection_select更新一个collection_select?

来自分类Dev

Rails 4:如何通过AJAX基于另一个collection_select更新一个collection_select?

来自分类Dev

rails 4-连接collection_select中的字段

来自分类Dev

Rails collection_select +引导程序下拉列表

来自分类Dev

Ruby on Rails-填写表单时更新collection_select

来自分类Dev

Rails:具有多个嵌套关联的集合的collection_select

来自分类Dev

Rails 4:collection_select是否不插入“ class”属性?

来自分类Dev

rails collection_select错误“未定义的方法显示”

来自分类Dev

在Rails中更新嵌套的fields_for和collection_select

来自分类Dev

Rails嵌套关联和多个collection_select

来自分类Dev

使用 collection_select 在 rails 中创建多条记录

来自分类Dev

为什么'autofocus:true'在Rails的collection_select上不起作用,而在text_field =

Related 相关文章

  1. 1

    如何从 collection_select rails 处理数组

  2. 2

    如何在Rails 4中禁用collection_select

  3. 3

    Rails 4动态Collection_Select

  4. 4

    Rails collection_select传递ID

  5. 5

    Rails处理collection_select的列表

  6. 6

    rails 4 collection_select多个嵌套属性无法正确保存

  7. 7

    Rails collection_select与f.collection_select

  8. 8

    Rails 4 +枚举:如何对collection_select中的值进行大写?

  9. 9

    如何在Rails的collection_select字段中放置“添加新”链接

  10. 10

    在Rails中使用collection_select时如何显示相关模型的属性

  11. 11

    Rails:如何在collection_select中添加自定义数据属性

  12. 12

    如何在Rails中通过JavaScript函数添加collection_select和text_area?

  13. 13

    如何在表单collection_select rails中将多个id作为数组传递?

  14. 14

    Ruby on Rails:如何更改collection_select下拉列表上的Foriegn Key值?

  15. 15

    在Rails中使用collection_select时如何显示相关模型的属性

  16. 16

    如何在仅显示具有特定属性的选项的rails中进行collection_select

  17. 17

    如何在Rails中使用嵌套属性编写collection_select

  18. 18

    Rails 4:如何通过AJAX基于另一个collection_select更新一个collection_select?

  19. 19

    Rails 4:如何通过AJAX基于另一个collection_select更新一个collection_select?

  20. 20

    rails 4-连接collection_select中的字段

  21. 21

    Rails collection_select +引导程序下拉列表

  22. 22

    Ruby on Rails-填写表单时更新collection_select

  23. 23

    Rails:具有多个嵌套关联的集合的collection_select

  24. 24

    Rails 4:collection_select是否不插入“ class”属性?

  25. 25

    rails collection_select错误“未定义的方法显示”

  26. 26

    在Rails中更新嵌套的fields_for和collection_select

  27. 27

    Rails嵌套关联和多个collection_select

  28. 28

    使用 collection_select 在 rails 中创建多条记录

  29. 29

    为什么'autofocus:true'在Rails的collection_select上不起作用,而在text_field =

热门标签

归档