我有这个rails代码:
<% status_a = [ ["DRAFT", "DRAFT"], ["OPEN", "OPEN"], ["CLOSE", "CLOSE"] ] %>
<%= form_for(:dash_action, url: brokers_dashboard_path ) do |f| %>
<%= f.select(:select_status, options_for_select(status_a), {}, selected:'OPEN' %>
<% end %>
运行时,会生成以下HTML代码:
<select selected="selected" name="dash_action[select_status]" id="dash_action_select_status">
<option value="DRAFT">DRAFT</option>
<option value="OPEN">OPEN</option>
<option value="CLOSE">CLOSE</option>
...
但我的期望是: 选中=“打开”而非“已选中”
为什么select方法没有做我想要的?
答案 0 :(得分:1)
请尝试以下代码段,默认值应为options_for_select
f.select :select_status, options_for_select(status_a, 'OPEN')