How Enums Have Evolved in Rails

Enums were first introduced in Rails 4.1, and since then, they have undergone significant improvements across versions.

Below is an overview of how Enums have changed over time:

Rails 4.1 (Initial Release)

Rails 5 and 6 Enhancements

Rails 7 Enhancements

Improved serialization for Enums when working with APIs. Made Enums easier to work with in ActiveRecord queries.

Rails 8 (Latest Version)

The most significant change in Rails 8 is the new way of defining Enums. Instead of

class User < ApplicationRecord
  enum status: { active: 0, inactive: 1, banned: 2 }
end

Rails 8 now recommends

class User < ApplicationRecord
  enum :status, { active: 0, inactive: 1, banned: 2 }
end

This change improves readability and brings Enums more in line with modern Rails conventions.