Ruby gem that replaces numeric IDs in Rails URLs with friendly slugs, including history, scopes, and localization options.
Overview
FriendlyId is an Active Record plugin for slugging and permalinks. Applications can expose URLs such as /states/washington instead of numeric primary keys while still resolving records by slug.
Version 5 requires Rails 4.0 or newer gems and expects FriendlyId 5.0.0 or greater. Setup adds a slug column, runs generators, and uses friendly.find in controllers instead of find unless the :finders module restores legacy behavior.
Advanced features include slug history, scoped slugs, reserved words, custom slug generators, and i18n support. Candidates allow alternate slug strings before falling back to sequences.
Documentation recommends the FriendlyId Guide for full usage, with Stack Overflow tagged friendly-id for questions.
Key features
- Slugged ActiveRecord lookups
- Slug history and versioning
- Scoped and reserved slugs
- Custom slug generators
- I18n-friendly slug support
- Multiple slug candidates
- Rails generator scaffolding
Use cases
- Pretty public Rails URLs
- Marketing-friendly resource paths
- Localized slugged content routes
- Migrating legacy numeric links