0
我想設置爲select
選定的屬性,但它似乎並不奏效Rails的選擇 - 默認選擇的值誤差
<%= f.fields_for :age_range, OpenStruct.new(@campaign.age_range) do |d| %>
<div class="form-group">
<%= d.label :min, "Age Range", :class => 'col-sm-2 control-label' %>
<div class="col-sm-2">
<%= d.text_field :min, :class => 'form-control' %>
<%= d.select :min, options_for_select(13..90), { include_blank: "Min Age", selected: '23' }, { class: 'form-control'} %>
</div>
<div class="col-sm-2">
<%= d.text_field :max, :class => 'form-control' %>
<%= d.select :max, options_for_select(13..90), { include_blank: "Max Age", selected: '23' }, { class: 'form-control'} %>
</div>
</div>
<div class="line line-dashed b-b line-lg pull-in"></div>
<% end %>
即使通過強制值我不能夠得到它選擇
從答案
<%= d.select :min, options_for_select((13..90), @campaign.age_range[:min]), { include_blank: "Min Age" }, { class: 'form-control'} %>
但更新是無法訪問分鐘的散列值來選擇的值
@campaign[:age_range] is a hash in the database
試'options_for_select((13..90),23)' – Nithin
HTTP:// apidock .COM /導軌/的ActionView /助手/ FormOptionsHelper/options_for_select – Pavan