How to use str_enum with Activemodel?
WillRadi opened this issue · comments
William Radi commented
Hello!
I'm trying to use str_enum within a module, and calling this module in a PORO. but the gem doesn't find Activemodels methods (validates
, scope
, and after_initialize
)
My code is like this:
module MonthEnumerations
include StrEnum::Model
str_enum :month, %w[january february march april may june july august september october november december]
end
class Period
include MonthEnumerations
end
William Radi commented
I found a solution...
Just add included do
block.. haha
module MonthEnumerations
extend ActiveSupport::Concern
included do
str_enum :month, %w[january february march april may june july august september october november december], scopes: false, default: nil
end
end
Thanks!