xxjjnn
xxjjnn

Reputation: 15249

rails list allowed values for enum

Given that in a model

enum_field :role, allowed_values: [:admin, :super_admin, :minion], default: :minion

Is there a built in way to access the list of allowed values without doing this:

def self.roles
  [:admin, :super_admin, :minion]
end
enum_field :role, allowed_values: self.roles, default: :minion

Upvotes: 0

Views: 126

Answers (1)

xxjjnn
xxjjnn

Reputation: 15249

oh...

model_name.roles

(I did try that but I did a typo)

Upvotes: 1

Related Questions