---
title: Use modern hash-based enum syntax
impact: MEDIUM
impactDescription: Use the more readable and explicit enum configuration in ActiveRecord.
tags: rails, active-record, readability, clarity
---

## Use modern hash-based enum syntax

Use the more readable and explicit enum configuration in ActiveRecord. Prefer mapping values to database integers explicitly via a hash to prevent accidental shifts if elements are reordered.

**Incorrect:**

```ruby
class Order < ApplicationRecord
  enum status: [:pending, :active, :shipped] # Dangerous if order changes
end
```

**Correct:**

```ruby
class Order < ApplicationRecord
  enum :status, { pending: 0, active: 1, shipped: 2 } # Explicit and safe
end
```

**Tools:** RuboCop (`Rails/EnumSyntax`)
