module ManualSlug::Mongoid::ClassMethods

Public Instance Methods

manual_slug(field, options = {}, callback = true) click to toggle source
# File lib/manual_slug/mongoid.rb, line 18
def manual_slug(field, options = {}, callback = true)
  options.merge!(permanent: true, history: true)
  slug field, options

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

  before_validation do
    self._slugs = self._slugs.map{ |s| s.strip }.reject {|s| s.blank? } if self._slugs

    if self._slugs.blank?
      self.build_slug
    end

    true
  end if callback
end