下拉列表中的选定值将在页面提交中重置。代码正在使用
<%=select_tag 'num_id', options_for_select(@numbers.collect{ |t| [t.firstno]}),:prompt => "Select"%>
我们如何在rails上的ruby中的select_tag中设置所选值。
答案 0 :(得分:1)
您可以将另一个参数传递给options_for_select
以设置所选选项
<%= select_tag 'num_id', options_for_select(@numbers.map(&:firstno), params[:num_id]), prompt: 'Select' %>
答案 1 :(得分:0)
select_tag选择值 -
options_for_select(@options, @selected_val)
示例:
options_for_select(1..8, 5) # creates options from range 1..8, with 5 as selected by default.