简体   繁体   中英

Rails Form Helpers, Radio Buttons

I'm trying to make my form for creating a new score (a score is just an integer value between 1 and 10). I've been reading through http://guides.rubyonrails.org/form_helpers.html for help and I want to use radio buttons to do this. I'm not doing it right though..I can't figure out how to associate the new the score with the right value selected. See below

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

Value is the name of the field in my scores table

Try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM