:选定的值将在页面提交中重置

时间:2013-03-12 11:27:52

标签: ruby-on-rails ruby ruby-on-rails-3

下拉列表中的选定值将在页面提交中重置。代码正在使用

<%=select_tag 'num_id', options_for_select(@numbers.collect{ |t| [t.firstno]}),:prompt => "Select"%>

我们如何在rails上的ruby中的select_tag中设置所选值。

2 个答案:

答案 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.