Repolode
norman

norman/friendly_id

A Ruby gem for Active Record that generates readable slugs so models can be found by a string like a name instead of a numeric id.

Stars
6,222
Forks
591
Open issues
33
Last commit
3 months ago

What is it?

FriendlyId is a Ruby gem for Active Record that creates human-readable URL slugs from model attributes. With it, a URL such as /states/washington can replace one that uses a numeric primary key like /states/4323454, and the model's find method accepts either form.

To use it, you add a slug column to a table, declare the attribute to slug from in the model with friendly_id, and switch controllers from Model.find to Model.friendly.find. The gem also provides a generator for its configuration file and migrations, and an option to skip raising RecordNotFound by passing allow_nil.

The project covers more advanced needs too, including slug history and versioning, i18n, scoped slugs, reserved words, and custom slug generators. It is MIT licensed and targets Rails 4.0 and later through version 5.x of the gem.

Key features

  • 01Generates slugs from model attributes and stores them in a dedicated column.
  • 02Lets find accept either a slug or a numeric primary key.
  • 03Keeps slug history so old URLs continue to resolve.
  • 04Supports scoped slugs, reserved words, and custom slug generators.
  • 05Includes i18n support for slugs.

Use cases

  • Building Rails pages whose URLs show a product, user, or article name instead of an ID.
  • Preserving old links after a record's title changes by using slug history.
  • Adding readable permalinks to an existing Rails application that already has records.

Quick start

  1. 1

    Add the gem to your Gemfile

  2. 2

    Install dependencies

    bundle install
  3. 3

    Generate the FriendlyId configuration file and migration

    rails generate friendly_id
  4. 4

    Run the migrations

    rails db:migrate

Things to know

  • Only works with Ruby on Rails and Active Record models.
  • Existing records need their slugs generated manually after adding FriendlyId.

Topics

#ruby#rails#active-record#slug#friendly-url#permalink#plugin

FAQ

What is friendly_id?
A Ruby gem for Active Record that generates readable slugs so models can be found by a string like a name instead of a numeric id. FriendlyId is a Ruby gem for Active Record that creates human-readable URL slugs from model attributes. With it, a URL such as /states/washington can replace one that uses a numeric primary key like /states/4323454, and the model's find method accepts either form.
Is friendly_id free to use? What license does it have?
friendly_id is open source under the MIT license. Check the license terms before using it in commercial products.
Is friendly_id still maintained?
Updated within 6 months. The last commit to friendly_id was on Aug 18, 2026.
What can I use friendly_id for?
Building Rails pages whose URLs show a product, user, or article name instead of an ID. Preserving old links after a record's title changes by using slug history. Adding readable permalinks to an existing Rails application that already has records.
How do I install friendly_id?
Add the gem to your Gemfile Install dependencies: bundle install Generate the FriendlyId configuration file and migration: rails generate friendly_id Run the migrations: rails db:migrate
Where can I get friendly_id?
The source code and installation instructions are on GitHub: https://github.com/norman/friendly_id

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects

Agnostic pagination library for plain Ruby that supports offset, keyset, search and calendar paginators across Rails, Sinatra and other frameworks.

5K447RubyMITWell maintainedUpdated yesterday