0

我正在使用此代码显示一个下拉列表。但是当我选择值并重新加载它时,我想显示选定的值。

<%= collection_select("server", "id",@ndt,"ndname", "ndname",:prompt => "Select Server") %>

就像在文本框中

<%= text_field_tag :name, params[:name]%>

重新加载时,它会在我们输入的文本框中显示名称。collection_tag 有同样的东西吗?

4

1 回答 1

0

使用该:selected选项。

<%= collection_select("server", "id", @ndt,"ndname", "ndname", 
  {:prompt => "Select Server", :selected => "id_of_your_object"}) %>
于 2012-12-18T10:57:51.570 回答