module ManualSlug::MongoidMod::ClassMethods

Public Instance Methods

manual_slug(field, options = {}, callback = true) click to toggle source
# File lib/manual_slug/mongoid_mod.rb, line 22
def manual_slug(field, options = {}, callback = true)
  unless options.key?(:permanent)
    options[:permanent] = true
  end
  unless options.key?(:history)
    options[:history] = true
  end

  slug field, options

  # we will create slugs manually when needed
  skip_callback :create, :before, :build_slug

  before_validation do
    if self._slugs.blank?
      self.build_slug
    else
      self._slugs = self._slugs.map{ |s| s.strip }.select {|s| !s.blank? }
    end
    true
  end if callback
end