Reputation: 2382
I have a enum in my Model that corresponds to column in the database.
The enum looks like:
enum efficency: { High: 0, Medium: 1, Low: 2 }
How can I get the key from the value
For example, i have the value 0, i need to fetch the value High.
Any help would be appreciated.
Upvotes: 19
Views: 22858
Reputation: 28305
Model.efficiencies.key(0) # => 'High'
Replace Model
with the actual name of your model.
Upvotes: 35