The project is in a healthy, maintained state
A :ulid attribute type for Active Record: every record gets its own ULID, optionally prefixed, generated when the record is built.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 1.4
 Project Readme

activerecord-ulid

A :ulid attribute type for Active Record. Every record gets its own ULID the moment it's built: sortable, unique, and readable in a URL.

Requires Ruby 4.0+ and Active Record 8.1+.

Installation

gem "activerecord-ulid"

Usage

ULIDs live in string columns:

create_table :users, id: :string do |t|
  t.string :invite_code
end

class User < ApplicationRecord
  attribute :id, :ulid
end

User.new.id # => "01JBQ8Z3X4M6V2N9R7T5K1W0HD"

Prefix them, Stripe style:

attribute :id, :ulid, prefix: "usr_" # => "usr_01JBQ8Z3X4M6V2N9R7T5K1W0HD"

Options:

  • prefix: prepended to the ULID.
  • nullable: true (or initial: false) leaves nil alone: no ULID is generated.
  • default: given explicitly wins over the generated ULID.

Assigning nil to a generating attribute gives it a fresh ULID.

Development

$ bundle exec rake test                 # padded_cell, Rails 8.1
$ RAILS_VERSION=edge bundle exec rake   # Rails main
$ dictator lint .

License

MIT. See LICENSE.txt.