On this page
Overview
AASM is a Ruby library for embedding finite state machines in classes. It defines states, events, transitions, guards, and callbacks and can run in plain Ruby or integrate with persistence layers such as ActiveRecord and Mongoid. Domains such as orders, approvals, and jobs can keep transition rules and side effects close to the model.
Features and best fit
Based on official documentation; not hands-on tested · Content checked:
Key features
Define states, events, and transitions with a Ruby DSL
Models declare an initial state and other states, then define event transitions between them. AASM also generates helpers for checking the current state and whether an event may run.
Sources: [1]
Attach guards and callbacks to transition logic
Guards can control events and transitions, while before/after, state enter/exit, error, and related callbacks place notifications or other side effects around the lifecycle.
Sources: [1]
Connect state changes to ActiveRecord and other persistence adapters
Alongside plain Ruby, AASM supports ActiveRecord, Mongoid, Dynamoid, and other adapters. ActiveRecord integrations include persisted bang events, transactions, and pessimistic locking.
Sources: [1]
Best fit
Fits Ruby applications that need explicit model-level transition rules
It is useful for order statuses, approval flows, background-job stages, and similar domains where allowed transitions should be represented as one state machine instead of scattered conditional logic.
Sources: [1]
Before adoption
AASM 6 requires Ruby 3+ and Rails 7+ for ActiveRecord integration
The current source declares AASM 6.0.0, and the v5-to-v6 migration guide drops Ruby 2 and Rails 6 support. Confirm the application runtime before upgrading.
Namespaced event method names change from v5 behavior
In v6, a namespaced state machine no longer defines the plain event method and instead defines the namespace-suffixed method directly. Applications calling the old plain names need migration.
Sources: [4]
Persisted bang events now raise by default on persistence failure
Version 6 changes whiny_persistence to true by default, so a failed persisted bang event raises instead of silently returning false. Existing error handling should be reviewed.
Sources: [4]
Official sources
- [1]AASM README(2026-10-03)
- [2]AASM version source(2026-10-03)
- [3]AASM gemspec(2026-10-03)
- [4]AASM v5 to v6 migration guide(2026-10-03)
- [5]AASM MIT license(2026-10-03)
Supplemental curator note
AASM is useful for orders, approvals, jobs, and other domains where allowed state transitions should be explicit in Ruby code. Version 6 changes runtime requirements, namespaced event methods, and persistence-failure behavior, so a 5.x upgrade should be treated as a breaking migration.
Try it in 3 steps
- 1
Add AASM to the Gemfile
AASM 6 requires Ruby 3+, and its ActiveRecord integration requires Rails 7+. Check the application's runtime first.
Add gem 'aasm' to Gemfile, then run bundle install - 2
Prepare a model with a state column
Follow the documented generator workflow to prepare the model and migration. Review generated changes when applying it to an existing model.
rails generate aasm Order state - 3
Define states and events, then test a transition
Define states, events, and transitions and verify the current state and event execution in the console.
Open app/models/order.rb, define the aasm block, then run rails console
Growth
Growth trends · Last 30 days
5,229 Stars
Trend data is still being collected.
Development activity
Last 90 days · weekly
- Commits (last 30 days)
- 0
- Open PRs
- 32
Development activity is still being collected.
Built with
Categories and tags
Categories
GitHub data
GitHub dataView detailed GitHub data
GitHub Topics
- state-machine
- ruby
- aasm
- transition
- activerecord
- mongoid
- hacktoberfest
- rails
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- CanCanCan5,681 Stars
2 shared tag(s) · Same language
centralize Rails authorization rules in Ability objects and reuse the same access policy across controllers, views, and queries
Ruby - Draper5,277 Stars
2 shared tag(s) · Same language
wrap Rails models with decorators and view models so presentation logic stays out of models and global helpers
Ruby - Jekyll51,707 Stars
1 shared tag(s) · 1 shared category(s) · Same language
generate blog-aware static sites from Markdown and Liquid
Ruby - Homebrew49,876 Stars
1 shared tag(s) · 1 shared category(s) · Same language
manage macOS and Linux software through the
Rubybrewpackage workflow - Vagrant27,211 Stars
1 shared tag(s) · 1 shared category(s) · Same language
define portable development environments across providers with a Vagrantfile
Ruby - Kamal14,627 Stars
1 shared tag(s) · 1 shared category(s) · Same language
deploy Dockerized web apps to bare metal or cloud VMs over SSH and switch traffic with kamal-proxy for zero-downtime releases
Ruby
Report incorrect information
Tell us if any listing information is incorrect or outdated.