Slugger plugin
Plugin details
Documentation
Install the plugin:
ruby script/plugin install http://svn.jesuscarrera.info/slugger
Examples
========
class Foo < ActiveRecord::Base # Stores permalink form of :title to the :slug attribute (default) has_slug :title # Stores a slug form of "#{category}-#{title}" to the :slug attribute (default) has_slug [:category, :title] # Stores slug form of "#{category}-#{title}" to the :permalink attribute has_slug [:category, :title], :to => :permalink # Add a scope has_slug :title, :scope => :blog_id # Change the slug on updates has_slug :title, :on_update => :overwrite # Change the slug on updates and redirect the old slug to the new one has_slug :title, :on_update => :redirect end
Use case
========
We need use slugs for the title of our blog posts (field 'title'). We have a field 'permalink' to store the slug in.
We have different blogs, so we can have the same slug for each blog.
On updates if the title change, we want to change the slug as well, but doing a 301 redirection from the old slug to the new.
class Post < ActiveRecord::Base belongs_to :post has_slug :title, :to => :permalink, :scope => :blog_id, :on_update => :redirect end
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (1 older version) | Last edited by: scott, 7 months ago

