From 38893fa515e65270cd2385c9a892ae2750dc10f2 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sat, 18 Aug 2012 11:09:20 +0100 Subject: [PATCH] Added RDoc. --- lib/slugtastic/model_additions.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/slugtastic/model_additions.rb b/lib/slugtastic/model_additions.rb index f5956fa..e64193c 100644 --- a/lib/slugtastic/model_additions.rb +++ b/lib/slugtastic/model_additions.rb @@ -1,6 +1,14 @@ module Slugtastic module ModelAdditions + # To generate a slug from another value, call has_slug in any + # ActiveRecord model and pass in the name of the slug attribute. + # By default the slug will be generated from the title attribute, but + # you can specify by adding :from => {attribute}. + # + # class Article < ActiveRecord::Base + # has_slug :slug, :from => :title + # end def has_slug name, options = { :from => :title } before_validation do |record| send("#{name}=", Slugtastic.generate_slug(send(options[:from]))) if send(name).nil? or send(name).blank?