ruby - How to get key name from a enum value in Rails? -
i have enum in model corresponds column in database.
the enum looks like:
enum efficency: { high: 0, medium: 1, low: 2 } how can key value
for example, have value 0, need fetch value high.
any appreciated.
model.efficiencies.key(0) # => 'high' replace model actual name of model.
Comments
Post a Comment