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?