1

I've got Rails 5 app where I'm using enum for status column in User table like below:

class User < ApplicationRecord
  enum status: {
    approved: 'approved',
    in_review: 'in review'
  }
end

When user have in_review status it shows me this:

2.4.5 :029 > User.first.status
 => "in_review"

Which allows me to do:

2.4.5 :031 > User.first.in_review?
 => true

Is there any way to display User.first.status as in review without underscore and in addition without losing enum function to get below result?

2.4.5 :029 > User.first.status
 => "in review"

2.4.5 :031 > User.first.in_review?
 => true

I know I could change the model to:

class User < ApplicationRecord
  enum status: {
    approved: 'approved',
    'in_review': 'in review'
  }
end

But then User.first.in_review? won't work.

mr_muscle
  • 2,536
  • 18
  • 61
  • 2
    The enum value is just some internal value and isn't really displayed. Wouldn't it be better to use `I18n` to translate your enum into a human readable name? See [Rails: How to use i18n with Rails 4 enums](https://stackoverflow.com/questions/22827270/rails-how-to-use-i18n-with-rails-4-enums) – 3limin4t0r Feb 10 '22 at 09:55

0 Answers0