Module: ManualSlug::Mongoid::ClassMethods

Defined in:
lib/manual_slug/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#manual_slug(field, options = {}, callback = true) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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