簡體   English   中英

Rails表單助手,單選按鈕

[英]Rails Form Helpers, Radio Buttons

我正在嘗試創建新分數的表單(分數只是1到10之間的整數值)。 我一直在閱讀http://guides.rubyonrails.org/form_helpers.html以獲得幫助,我想使用單選按鈕來做到這一點。 我沒有做正確的事..我不知道如何將新的分數與選定的正確值相關聯。 見下文

<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 %>

值是我的分數表中字段的名稱

嘗試

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM