Rails 7 deprecate defining enum with keyword arguments


Rails 7 deprecate enum definition by keyword arguments, From Rails 7.3 this old syntax will not be available.This is important for those who are willing to upgrade their rails version and already using the older syntax for defining Enum. In case you are wondering what is the new Rails syntax for defining rails, checkout this article.

# Before Rails 7.3

class User < ApplicationRecord
  # This syntax is valid
  enum status: [:active, :inactive]
end

# After Rails 7.3

class User < ApplicationRecord
  enum :status, [:active, :inactive]
end

Example of new enum syntax with Hash as enum options.

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

Refer to this Commit for more details.

💡 Did You Know?

Rails 7 Introduces validations for Enum



Discover More Insights: Explore Our Recommended Posts!