Module: FriendlyId::Slugged::Model

Included in:
ActiveRecordAdapter::SluggedModel
Defined in:
lib/friendly_id/slugged.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#slugObject

Returns the value of attribute slug.



41
42
43
# File 'lib/friendly_id/slugged.rb', line 41

def slug
  @slug
end

Instance Method Details

#find_slugObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/friendly_id/slugged.rb', line 43

def find_slug
  raise NotImplementedError
end

#friendly_id(skip_cache = false) ⇒ Object

The friendly id.

Parameters:



58
59
60
61
62
63
# File 'lib/friendly_id/slugged.rb', line 58

def friendly_id(skip_cache = false)
  if friendly_id_config.cache_column? && !skip_cache
    friendly_id = send(friendly_id_config.cache_column)
  end
  friendly_id || (slug.to_friendly_id if slug?)
end

#friendly_id_configObject



47
48
49
# File 'lib/friendly_id/slugged.rb', line 47

def friendly_id_config
  self.class.friendly_id_config
end

#friendly_id_statusObject

Get the FriendlyId::Status after the find has been performed.



52
53
54
# File 'lib/friendly_id/slugged.rb', line 52

def friendly_id_status
  @friendly_id_status ||= Status.new(:record => self)
end

#normalize_friendly_id(string) ⇒ String

Clean up the string before setting it as the friendly_id. You can override this method to add your own custom normalization routines.

Parameters:

Returns:



69
70
71
# File 'lib/friendly_id/slugged.rb', line 69

def normalize_friendly_id(string)
  string.normalize_for!(friendly_id_config).to_s
end

#slug?Boolean

Does the instance have a slug?

Returns:

  • (Boolean)


74
75
76
# File 'lib/friendly_id/slugged.rb', line 74

def slug?
  !! slug
end