2016-01-10 21 views
1

表單提交值爲零,但我選擇了一個值。如何使用簡單形式的寶石來傳遞選擇輸入的值?

<%= 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> 
+0

只是一個忠告:請記住,Rails及其生態系統的設計考慮了Web應用程序的開發。通常情況下,問題已經解決 - 例如初始化表單的值。你試圖重新發明車輪越多,你將面臨的問題越多。堅持其慣例,你會很開心。 :) –

回答

1

你會做的更好使用simple_formsyntax

<%= 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 %> 
+0

如果上述不起作用,您需要提交提交後發送給控制器的參數。 –

+1

它正在工作。這是我有一個錯字的參數。謝謝,瑞克。你和我的作品。 –