21

I wanted to get the array of symbols(:foo,:bar) available in an Enum field(:status).

   class MyModel < ActiveRecord::Base
     enum status: [:foor, :bar]
   end
2

1 Answer 1

35

As explained in the Enum guide, if you have an enum field called status you access the mapping using the plural form:

MyModel.statuses
 => {"foor"=>0, "bar"=>1}

The keys are the enum values, the values are an incremental integer assigned based on the order of the enum definition.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.