Module: Slug::InstanceMethods

Defined in:
lib/slug/slug.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



62
63
64
# File 'lib/slug/slug.rb', line 62

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#reset_slugObject

Overwrite existing slug based on current contents of source column.



53
54
55
# File 'lib/slug/slug.rb', line 53

def reset_slug
  set_slug(:force => true)
end

#set_slug(opts = {}) ⇒ Object

Sets the slug. Called before create. By default, set_slug won't change slug if one already exists. Pass :force => true to overwrite.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/slug/slug.rb', line 40

def set_slug(opts={})
  validate_slug_columns      
  return unless self[self.slug_column].blank? || opts[:force] == true

  original_slug = self[self.slug_column]
  self[self.slug_column] = self.send(self.slug_source)

  strip_diacritics_from_slug
  normalize_slug
  assign_slug_sequence unless self[self.slug_column] == original_slug # don't try to increment seq if slug hasn't changed
end

#to_paramObject

Overrides to_param to return the model's slug.



58
59
60
# File 'lib/slug/slug.rb', line 58

def to_param
  self[self.slug_column]
end