acts_as_slugable Rails plugin
Generates a URL slug/permalink based on a field (i.e. title).
The slug is generated on save and create actions.
Here is the source code.
Time for an experiment. Updates to plugins, gems and other code will be announced at http://twitter.com/TheCHANGELOG. Follow along so you can receive updates without having to check back. You can also subscribe to the Atom feed.
Installation
./script/plugin install http://code.dunae.ca/acts_as_slugable
Usage example
Generate a URL slug based on the title of a Page record and store it in url_slug. Slug will be unique within the parent_id.
class Page < ActiveRecord::Base acts_as_slugable :source_column => :title, :target_column => :url_slug, :scope => :parent end
Testing
To execute the unit tests run the default rake task (rake default). To execute the unit tests but preserve to debug log run rake test.
The unit tests for this plugin use an in-memory sqlite3 database.
Credits
Created by Alex Dunae (http://dunae.ca/), 2006-07, though it takes a village to raise a plugin:
- Thanks to Andrew White for fixing a conflict with acts_as_list.
- Thanks to Philip Hallstrom for pointing out some redundant code.