Awesome Open Source
Awesome Open Source


Build Status

Coverage Status

Checkout for more details.

A gem for generating url-safe permalink-string from any other attribute in the same ActiveRecord model.

Make you urls look like '/users/olkarls' instead of '/users/1'.


put this in your gemfile:

gem "has_permalink"

And run in your terminal:

bundle install

If your model doesn’t already have the permalink attribute you can run this generator command:

rails g has_permalink [Model]

That will generate a migration which adds a permalink attribute [Model] and indexes it. Don’t forget to:

rake db:migrate


class Post < ActiveRecord::Base

The plugin assumes that the permalink attribute is generated from the title attribute but it can be changed by providing an argument like this:

class Post < ActiveRecord::Base
  has_permalink :heading

The permalink attribute is generated by the before_validation callback and is only transformed if it’s blank. If it's not blank and you want to regenerate it use:


Use this syntax your controller:

def show
  @post = Post.find_by_permalink(params[:id])


2011-06-25, version 0.1.1

  • Only override find if there is only one argument which is a string.

2011-06-20, version 0.1.0

  • Auto resolve duplication, if wanted
  • Merged Anoopr's fork, thanks!


  • Override find to query the permalink attribute.

2011-03-12, version 0.0.8

  • Removed the Rails 3 dependency.
  • Updated homepage.

2011-02-01, version 0.0.7:

  • Permalinks can't start or end with '-'.
  • Added class method for use in rake task.

2011-01-31, version 0.0.6:

  • Fixed a bug where the permalink could sometimes remove characters.

Copyright (c) 2009 - 2011 Ola Karlsson, released under the MIT license

Bitdeli Badge

Alternatives To Has_permalink
Select To Compare

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Ruby (225,272
Plugin (113,349
Ruby On Rails (68,337
Version (20,554
Seo (3,404