ruby on rails - Share enum declaration values with multiple attributes -
i want have class several attributes saves weekdays numeric values.
summary_weekday :integer collection_weekday :integer
i thought map integers values using enum 2 declarations:
enum summary_weekday: %w(monday tuesday wednesday thursday friday saturday sunday) enum collection_weekday: %w(monday tuesday wednesday thursday friday saturday sunday)
but rails doesn't accept that, cannot define same value twice in same class.
you tried define enum named "summary_weekday" on model "questioncategory", generate instance method "monday?", defined enum.
how can solve this?
as of rails 5.0 can use _prefix
or _suffix
options when need define multiple enums same values. if passed value true, methods prefixed/suffixed name of enum.
class invoice < activerecord::base enum verification: [:done, :fail], _prefix: true end
it possible supply custom prefix.
class invoice < activerecord::base enum verification: [:done, :fail], _prefix: :verification_status end
Comments
Post a Comment