I know there are some plugins out there that do the same, but this one fits my needs.
Add to your posts the permalink attribute.
add_column :posts, :permalink, :null => false add_index :posts, :permalink
And use it on your models.
class Post < ActiveRecord::Base permalink :title permalink :title, :slug # If you want to use a custom attribute. end
So now you can find your posts with:
class Posts < ApplicationController def show @post = Post.find_by_permalink_and_status!(params[:id]) end end
Francesc Esplugas - francescesplugas.com
Copyright © 2008-2009 Francesc Esplugas Marti, released under the MIT license