PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 19, 2022

[FIXED] How to use integer radio buttons

 July 19, 2022     integer, radio-button, ruby, ruby-on-rails     No comments   

Issue

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.


Solution

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


Answered By - Rajarshi Das
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing