lipsum
lipsum

Reputation: 969

How should I get hash defined as enumerize?

I use enumerize in my rails project like this:

class User < ActiveRecord::Base
  extend Enumerize

  enumerize :sex, in: {
    male: 0,
    female: 1,
    other: 2,
  }, predicates: { prefix: false }

...

end

Now I want to get the hash passed to the enumerize with in:, so that I can use the pairs of the values and ints on the view file. (I know we should have stored them as a table in DB, not enumerize. But we can't change it right now)

I found User.sex.values() returns a list like ["male", "female", "other]. But Can I get the hash itself?

Upvotes: 0

Views: 1136

Answers (1)

Andrew_tainton
Andrew_tainton

Reputation: 271

If you are using active record you should be using

You would be able to call User.sexes to get the key value pairs.

I am not sure why you are looking to use Enumerize.

Upvotes: 1

Related Questions