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

  • Home
  • SEARCH
  • 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 3980652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:18:58+00:00 2026-05-20T05:18:58+00:00

I have a Person table in my database and I have a column named

  • 0

I have a Person table in my database and I have a column named person_type. I don’t want a database model for person_type as it will always be either “Volunteer” or “Participant”. Where would I create a static array to hold these values and how would I bind that array to the Ruby on Rails select helper? Would it be best to just create a select helper?

Thanks!

  • 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-20T05:18:59+00:00Added an answer on May 20, 2026 at 5:18 am

    The simplest way to implement this is by having a constant in your Person model:

    class Person < ActiveRecord:Base
      PERSON_TYPES = ["Volunteer", "Participant"]
    end
    

    which you can then access using the select helper:

    f.select(:person_type, Person::PERSON_TYPES)
    

    If you need to consider i18n, it only needs a few slight modifications.

    Given these entries in your i18n files:

    # config/locales/en.yml
    person_types:
      volunteer: "Volunteer"
      participant: "Participant"
    
    # config/locales/de.yml
    person_types:
      volunteer: "Freiwillige"
      participant: "Teilnehmer"
    

    You can update your model and view thus:

    # app/models/person.rb
    class Person < ActiveRecord:Base
      # The values have been made lower-case to match the conventions of Rails I18n
      PERSON_TYPES = ["volunteer", "participant"]
    end
    
    # app/views/people/_form.html.erb
    <%= f.select :person_type, Person::PERSON_TYPES.map { |s| [I18n.t("person_types.#{s}"), s] } %>
    

    This will give you the HTML you’re after:

    <!-- assuming the current I18n language is set to 'de' -->
    <select name="person[person_type]">
      <option value="volunteer">Freiwillige</option>
      <option value="participant">Teilnehmer</option>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails model called Person which has database table columns for first_name
I have a database structure that has a Person table which contains fields such
I have a table Person which contains 2 fields.In my another database i have
Suppose I have table Person table Employee, which inherits Person. I want to get
I have table with date/time column and person column. Each person has multiple records
In most of my databases that I have created I've always named my column
I have a user table in my mysql database that has a password column.
I have a database scheme with versioning data rows, e.g. Table Person has the
I have people in my database in the PERSON table, and each person is
I have a table named KEYWORDS with a column named ENTRY of VARCHAR(10). Would

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.