Module: MLS::Slugger::ActiveRecordBaseSluggerExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/mls.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#set_slugObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/mls.rb', line 68

def set_slug
  generated_slug = if self.slugger[:proc].is_a?(Proc)
    if (self.slugger[:proc].arity == 1)
      self.slugger[:proc].call(self)
    else
      self.slugger[:proc].call
    end
  else
    send(self.slugger[:proc])
  end
  generated_slug = generated_slug ? generated_slug.split('/').map(&:parameterize).join('/') : nil

  if self.slugger[:options][:history]
    self.slugger[:slug_was] = self.slug
  end

  if [:before_validation, :after_validation, :before_save, :before_create].include?(self.slugger[:options][:trigger])
    self.slug = generated_slug
  else
    update_column(:slug, generated_slug) if slug != generated_slug
  end
end

#to_paramObject

TODO: Test



64
65
66
# File 'lib/mls.rb', line 64

def to_param
  slug? ? slug : super
end