如何使用简单形式gem传递选择输入的值?

时间:2016-01-10 20:37:32

标签: ruby-on-rails ruby select simple-form

表单正在将值提交为nil,尽管我选择了一个值。

<%= simple_form_for @offer do |f| %>
<div class="form-group">
<%= f.label :days_per_turn, "Days Per Turn" %>
<%= f.select :days_per_turn, [ 1, 2, 3, 5, 7, 10, 14 ], selected: '1' %>
<%= f.label :play_as, "I Play As" %>
<%= f.select :play_as, [ 'Random', 'White', 'Black' ], selected: 'Random' %>
<%= f.label :rated, "Rated" %>
<%= f.select :rated, [ 'Yes', 'No', 'Takeback' ], selected: 'No' %>
</div>
<div class="actions">
  <%= f.submit "Submit", :class => 'btn btn-primary' %>
</div>
  

1 个答案:

答案 0 :(得分:1)

您最好使用simple_form syntax

<%= simple_form_for @offer do |f| %>
   <div class="form-group">
      <%= f.label :days_per_turn, "Days Per Turn" %>
      <%= f.input :days_per_turn, collection: [[1,1],[2,2],[3,3],[5,5],[7,7],[10,10],[14,14]], selected: 1 %>

      <%= f.label :play_as, "I Play As" %>
      <%= f.input :play_as, collection: [['Random', :random], ['White', :white], ['Black', :black]], selected: :random %>

      <%= f.label :rated, "Rated" %>
      <%= f.input :rated, collection: [['Yes', :yes],['No', :no], ['Takeback', :takeback]], selected: :no %>
   </div>
   <div class="actions">
      <%= f.submit "Submit", :class => 'btn btn-primary' %>
   </div>
<% end %>
相关问题