Class: Slug

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/friendly_id/active_record_adapter/slug.rb

Overview

A Slug is a unique, human-friendly identifier for an ActiveRecord.

Instance Method Summary collapse

Instance Method Details

#current?Boolean

Whether this slug is the most recent of its owner’s slugs.

Returns:

  • (Boolean)


18
19
20
# File 'lib/friendly_id/active_record_adapter/slug.rb', line 18

def current?
  sluggable.slug == self
end

#outdated?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/friendly_id/active_record_adapter/slug.rb', line 22

def outdated?
  !current?
end

#to_friendly_idObject



26
27
28
# File 'lib/friendly_id/active_record_adapter/slug.rb', line 26

def to_friendly_id
  sequence > 1 ? friendly_id_with_sequence : name
end

#validate_nameObject

Raise a FriendlyId::SlugGenerationError if the slug name is blank.



31
32
33
34
35
# File 'lib/friendly_id/active_record_adapter/slug.rb', line 31

def validate_name
  if name.blank?
    raise FriendlyId::BlankError.new("slug.name can not be blank.")
  end
end