Rails 7 deprecate defining enum with keyword arguments
By Abhishek Kanojia on February 13, 2024
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?