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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:09:17+00:00 2026-05-15T02:09:17+00:00

I have a relatively simple problem. I have a model named Item which I’ve

  • 0

I have a relatively simple problem. I have a model named Item which I’ve added a status field. The status field will only have two options (Lost or Found). So I created the following array in my Item model:

STATUS = [ [1, "Lost"], [2, "Found"]]

In my form view I added the following code which works great:

<%= collection_select :item, :status, Item::STATUS, :first, :last, {:include_blank => 'Select status'}  %>

This stores the numeric id (1 or 2) of the status in the database. However, in my show view I can’t figure out how to convert from the numeric id (again, 1 or 2) to the text equivalent of Lost or Found.

Any ideas on how to get this to work? Is there a better way to go about this?

Many thanks,
Tony

  • 1 1 Answer
  • 3 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-15T02:09:18+00:00Added an answer on May 15, 2026 at 2:09 am

    You can define a method in your Item model:

    class Item < ActiveRecord::Base
      #
      def status_str
        Item::STATUS.assoc(status).last
      end
    end
    

    And use it:

    item.status_str # => "Lost" (if status == 1)
    

    Or you can check out enum_fu plugin:

    class Item < ActiveRecord::Base
      #
      acts_as_enum :status, ["Lost", "Found"]
    end
    

    and then item.status gives you string value:

    item.status # => "Lost"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a computational geometry problem that I feel should have a relatively simple
I have a relatively simple question. Will using PHP guarantee that a form is
I have two relatively simple codes. One main activity and one intent service. Main
I have a relatively simple class which deletes a post: function delete_post($postid, $reason){ //Stuff
I have a relatively simple application which I need to make native Mac OSX
I have a relatively simple query joining two tables. The Where criteria can be
I have a problem with a relatively simple query and the execution plan Access
I have a relatively simple problem bat as yet I haven found the most
I have a relatively simple form which asks a variety of questions. One of
I have a set of classes and interfaces which have a relatively simple hierarchy,

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.