MrMatthias MrMatthias - 4 years ago 157
Ruby Question

How to use integer radio buttons

What is the simplest way to represent an integer attribute with a limited number of valid values as radio buttons?

How can I use the formhelper to achieve this? I only see examples that use string values.

Answer Source

You can try

   <%= form_for :model do |f| %>
    <% 1.upto(10) do |i| %>
      <%= f.radio_button :integer, i %> #integer is the model field
    <% end %> 
   <% end %>

or

<%= form_tag do %>
<% 1.upto(10) do |i| %>
  <%= radio_button_tag :name, i %>
<% end %>
<% end %>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download