Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4614098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:38:56+00:00 2026-05-22T01:38:56+00:00

So this is sort of both a question about how to structure boolean sort

  • 0

So this is sort of both a question about how to structure boolean sort of selections and the form fields themselves. For example If the user when signing up has to choose a team (and for demonstration purposes) like “wizard” or “archer”, so like should I have:

field :wizard, type: Boolean
field :archer, type: Boolean

However they can only be one or the other, so how do I structure my forms with radio fields so that users can only select one or the other, I’m not sure if I’m doing this right so in my form say i’d have something like:

<p><%= f.label "wizard" %><%= radio_button(:user, :wizard, "True") %></p>
<p><%= f.label "archer" %><%= radio_button(:user, :archer, "True") %></p>

But so this doesn’t work because you can select as many items as you want. How do I prevent the user from selecting more than one radio selection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:38:56+00:00Added an answer on May 22, 2026 at 1:38 am

    Radio buttons don’t quite work across different fields in HTML. In order for them to be related such that you can only pick one, they must have the same value for the name attribute. Yours are being generated with name values of “user.wizard” and “user.archer”. You would need something like:

    <p><%= f.label "wizard" %><%= radio_button(:user, :role, "wizard") %></p>
    <p><%= f.label "archer" %><%= radio_button(:user, :role, "archer") %></p>
    

    and then have code in the model that plucks off the selected role to set your boolean fields appropriately.

    Overall though, I would recommend changing your data model to have role as a string field, or normalize and make role_id a real field, pointing to a separate table which contained the roles (user belongs_to :role, role has_many :users). In that way, if you add a new role, you won’t need to change any code, just add a row to the table. You can still have the boolean methods on the User model (e.g., user.is_wizard?), but they would be calculated based on the role.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a section of makefile that has this sort of structure: bob: ifdef
This question sort of covers both ServerFault.com and here, but this seems more programming
This is sort of SQL newbie question, I think, but here goes. I have
This is sort of a follow-up to this question . If there are multiple
I'm sure this question has been answered before, but I don't think I'm using
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I've run across this sort of thing on multiple websites and was wondering what
How would you describe the running time of this sort, given a function sorted
I have this big data-entry sort of page, a table kind of layout using
I am using this command: cut -d: -f2 To sort and reedit text, Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.