public
Description: Plugin to create permalinks without id's
Homepage: http://www.reloc.org/technology/permalink_slugs/
Clone URL: git://github.com/reloc/permalink_slugs.git
name age message
file README.markdown Wed Feb 11 05:29:54 -0800 2009 Updated doc [reloc]
file init.rb Wed Feb 11 02:56:20 -0800 2009 first commit [reloc]
file install.rb Wed Feb 11 02:56:20 -0800 2009 first commit [reloc]
directory lib/ Wed Feb 11 02:56:20 -0800 2009 first commit [reloc]
directory tasks/ Wed Feb 11 02:56:20 -0800 2009 first commit [reloc]
directory test/ Wed Feb 11 02:56:20 -0800 2009 first commit [reloc]
README.markdown

PermalinkSlugs

A Rails plugin that adds a permalink method to the models it's applied to. The permalink returned can be defined by the user and doesn't use the id to make it unique. instead it does validate the slug for the model for uniqueness when you create it.

This is my first Rails plugin, please feel free to contact me for enhancement suggestions.

Prerequisites

  • You need the to_slug plugin. script/plugin install git://github.com/ludo/to_slug.git
  • All models with a permalink need a slug attribute.
  • If you want to have nice permalinks for nested pages i recommend awesome_nested_set. script/plugin install git://github.com/collectiveidea/awesome_nested_set.git

Usage

In your model:

permalink_slugs :default => :name, :slug => :slug, :scope => nil, :parent => nil
  • :default is the name the slug is being generated from if no slug given. default is :name
  • :slug is the name of the field where the slug is stored in the model. default is :slug
  • :scope if you want to validate the uniqueness of the slug depending on another field. use it just like with validates_uniqueness_of. no default.
  • :parent if you use awesome_nested_set set this to :parent_id. no default.

Get a permalink:

model.permalink
# => "/slug_value"

For nested pages:

model.permalink
# => "/mainpage/subpage"

Todos

  • Write Tests

  • There's a issue with awesome_nested_set where slugs are not validated correctly after create. update works fine.

Copyright (c) 2008 Gerold Böhler, released under the MIT license