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 8475197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:49:51+00:00 2026-06-10T17:49:51+00:00

For database columns that are integers that represent strings, what is the best way

  • 0

For database columns that are integers that “represent” strings, what is the best way to show the string value in the view?

For example, if I collect “payment_method” values as integers in my form as follows:

<%= f.select :payment_method, { "Visa" => "1", "Mastercard" => "2", "Amex" => "3"} %>

How can I show the saved integer as a string in my view files? What can I add to my model, so that

<%= @relevantvariable.payment_method %> 

or something similar returns string values like “Visa”, “Mastercard” or “Amex” instead of their respective integer values?

Thanks much for handling such a basic question!

  • 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-06-10T17:49:53+00:00Added an answer on June 10, 2026 at 5:49 pm

    Either don’t use an integer value, and store the payment method directly as a string in the db, or create a PaymentMethod model.

    With the association set up, you’d be able to refer to the name of the payment method as so:

    <%= @relevantvariable.payment_method.name %> 
    

    Don’t try to manually handle lists of names / ids – that will quickly get unmanageable.

    Edit: after reading your comment, if you went with the first option and stored a string in the table, definitely don’t allow the user to type the value directly, maintain a list on the model (or similar), that you seed your dropdown from, that way you’re still constraining the possible values. You could even add a custom validator if you want to be certain what you putting in the database.

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

Sidebar

Related Questions

I need to parse the value of a database column that generally contains integers,
I'm writing a lightweight ORM that can map database columns to instance fields with
Given a database that has numerous repeating columns used for auditing and versioning, what
I have a database that has the following columns: ------------------- id|domain|hit_count ------------------- And I
I have several columns in a MySQL database that I would like to add
I have a rather large database that has alot of decimal columns in alot
I have a few columns in an SQL server 2008 R2 database that i
i have one database, and it contains some columns. My requirement is that how
I'm trying to create a check on a few columns in my database that
In my database I have a 2 columns (Kind and Priority) that are of

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.