Default Enum in Rails 6
By Abhishek on August 2, 2020
Rails 6 provides a way to define default enum value. Let’s see how it works with an example.
For this example we are using Rails alpha.
Default enum in action
Post model, with status as
published, and will be using
draft as default will be something like:
class Post < ApplicationRecord enum status: %i[draft published], _default: :draft end
On checking a new post’s status turns out to be a
draft. In previous versions of Rails this turns out to be