Enum in Rails model

Rails doesn’t have choices like Django. There are few steps to create choice.

  1. Generate model
rails generate model Todo title: string status: integer

  1. Edit generated model:
class Todo < ApplicationRecord
  enum status: { 'Not Done': 0, 'Done': 1 }
end

  1. Edit generated migration file to add default status:
class CreateTodos < ActiveRecord::Migration[7.2]
  def change
    create_table :todos do |t|
      t.string :title
      t.integer :status, default: 0 # <- add default here

      t.timestamps
    end
  end
end

Too much work and broken connections. Django wins here.