[英]Rails - How do display an integer in options_from_collection_for_select?
I wish to display a list a selectable list of 1-42 on a form. 我希望在表单上显示一个列表(1-42的可选列表)。 I have an array assignment in the controller's new me to create the list: 我在控制器的新手中有一个数组分配来创建列表:
@cabinet_position_list = (1..42).to_a
The number will be assigbed to device.position but I can't figure out how to display the numbers in the box. 该数字将被分配给device.position,但我不知道如何在框中显示数字。 Here's the best I've come up with on the form: 这是我在表格上提出的最好的:
<%= f.select :position, options_from_collection_for_select(@cabinet_position_list, "position", "?????") %>
You don't need options_from_collection_for_select in this case. 在这种情况下,您不需要options_from_collection_for_select。 Just: 只是:
f.select :position, @cabinet_position_list
or 要么
f.select :position, (1..42).to_a
options_for_select(@cabinet_position_list)
应该可以工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.