New to Rails 3? Check out the Ruby on Rails 3 Tutorial book and screencast.

A book and screencast series showing you how to develop and deploy industrial-strength Rails apps in a direct, step by step way. The screencast series includes 12 lessons over more than 15 hours! Get the best "over the shoulder" experience of following what a top Rails 3 developer does when building an app today. Click here to learn more.

FriendlyID: A Slugging and Permalink Plugin for ActiveRecord

In Plugins

friendlyid.pngFriendlyID, a plugin by Normal Clarke, Adrian Mugnolo, and Emilio Tagua, describes itself as "the Swiss Army bulldozer of slugging and permalink plugins for ActiveRecord." In layman's terms, FriendlyID helps you get out of numerical ID hell and into an easily organized heaven of well formatted, textual slugs and IDs for your Rails apps.

For example, let's say you have a User model, you can add the following line:

has_friendly_id :login

And now you can write code like this (taken from the README):

@member = Member.find("joe")   # the old Member.find(1) still works, too.
@member.to_param               # returns "joe"
redirect_to @member            # The URL would be /members/joe

FriendlyID's Github page has a really solid README with further examples - it gets way more advanced than the simple example above!

Also..lapsusss.png Time Tracking without Timers: Lapsus runs in the background and knows what project you're working on. Find out how long that last project took without the hassle of updating a timer. Watch the screencast or sign up for the Beta.

Post to Twitter Tweet This Post

Vaguely Related Posts (Usually)

2 Comment Responses to “FriendlyID: A Slugging and Permalink Plugin for ActiveRecord”

  1. #1
    Nazar Says:

    I am a big fan of FriendlyID.

    It does, however, require some attention when returning a list of Slugged objects to avoid On query situations (i.e. include => :slugs ) ... this probably has been addressed in later versions (I am still on the Rails 2.1.3 compatible version).

    Excellent plugin gents!

  2. #2 » Blog Archive » Rails Reading - Sept 21, 2009 Says:

    [...] FriendlyID: A Slugging and Permalink Plugin for ActiveRecord [...]

Leave a Reply