Rails Enum with prefix/suffix
[enum]:http://api.rubyonrails.org/classes/ActiveRecord/Enum.html
Today I learned that Rails 5 released new options for [enum][] definition: _prefix
and _suffix
.
class Conversation < ActiveRecord::Base
enum status: [:active, :archived], _suffix: true
enum comments_status: [:active, :inactive], _prefix: :comments
end
conversation.active_status!
conversation.archived_status? # => false
conversation.comments_inactive!
conversation.comments_active? # => false
h/t @joshuadavey
Tweet