Module: ManualSlug::ClassMethods

Defined in:
app/models/concerns/manual_slug.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 'app/models/concerns/manual_slug.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 }.select {|s| !s.blank? }

    if self._slugs.empty?
      self.build_slug
    end

    true
  end if callback
end