简体   繁体   English

Rails-如何在options_from_collection_for_select中显示整数?

[英]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.

相关问题 Rails上options_from_collection_for_select的工具提示 - Tooltip for options_from_collection_for_select on Rails 如何在rails中添加options_from_collection_for_select的数据属性 - How to add data attribute for options_from_collection_for_select in rails 如何在Rails中显示html options_from_collection_for_select - How to show html in rails options_from_collection_for_select rails options_from_collection_for_select - 在API的下拉列表中显示正确的数据,用户从下拉列表中选择 - rails options_from_collection_for_select - display proper data in dropdown from API and user selects from dropdown 带有options_from_collection_for_select的Rails select_tag CSS - Rails select_tag css with options_from_collection_for_select Rails options_from_collection_for_select显示除当前用户外的所有用户 - Rails options_from_collection_for_select display all users except current user Rails-options_from_collection_for_select-根据下拉菜单中当前突出显示的内容显示其他字段? - Rails - options_from_collection_for_select - Display other fields based on what is currently highlighted in dropdown? Rails显示来自options_from_collection_for_select的索引结果 - Rails show index results from options_from_collection_for_select Rails options_from_collection_for_select返回唯一的年份值 - Rails options_from_collection_for_select return unique year values rails options_from_collection_for_select ajax请求 - rails options_from_collection_for_select ajax request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM