2016-04-28 171 views
0

我試圖讓我的表單創建一個新的分數(分數只是1到10之間的整數值)。我一直在閱讀http://guides.rubyonrails.org/form_helpers.html尋求幫助,我想用單選按鈕來做到這一點。雖然我做得不對,但我無法弄清楚如何將新分數與選定的正確值相關聯。見下面Rails表單助手,單選按鈕

<h2 style="text-align:center"> 
     On a scale from 1-10, how likely are you to recommend this site to a friend or colleague? 
     </h2> 
     <%= form_for @score do |s| %> 
      <%= radio_button_tag(:value, 1) %> 
      <%= label_tag(:value, "1") %> 
      <%= radio_button_tag(:value, 2) %> 
      <%= label_tag(:value, "2") %>    
      <%= s.submit "Submit" %> 
     <% end %> 

值是在我的成績表中的字段的名稱

回答

0

嘗試

<%= form_for @score do |s| %> 
    <%= s.radio_button :value, 1, id: "v_1" %> 
    <label for = "v_1">Label 1</label> 
    <%= s.radio_button :value, 2, id: "v_2" %> 
    <label for = "v_2">Label 2</label> 
    <%= s.submit "Submit" %> 
<% end %>