我正在使用select_tag
并且当我更新所选值时未存储
当我更新:name,:tag value get first option
edit.html.erb
<%= form_for(@name) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :lname%><br />
<%= f.text_field :lname%>
</div>
<div class="field">
<%= f.label :tag %><br />
<%= f.select :tag, "<option>1</option><option>2</option><option>3</option><option>4</option>".html_safe %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
解决方案
<%= f.collection_select(:tag, [1,2], :to_i, :to_s, :prompt => 'Categories') %>
答案 0 :(得分:1)
也许?
= f.select :tag, (1..4).to_a, :prompt => '---'
答案 1 :(得分:0)
答案 2 :(得分:0)
试试这个
<%= f.select "tag", "<option value="1">1</option><option value="2">2</option></select>".html_safe %>
阅读http://ashleyangell.com/2009/11/form-select-helper-in-ruby-on-rails/
答案 3 :(得分:0)
<强>解决方案强>
<%= f.collection_select(:tag, [1,2], :to_i, :to_s, :prompt => 'Categories') %>