module FriendlyId::Model

Instance methods that will be added to all classes using FriendlyId.

Public Class Methods

included(model_class) click to toggle source
# File lib/friendly_id/base.rb, line 245
def self.included(model_class)
  return if model_class.respond_to?(:friendly)
end

Public Instance Methods

dup() click to toggle source

Clears slug on duplicate records when calling `dup`.

Calls superclass method
# File lib/friendly_id/base.rb, line 269
def dup
  super.tap { |duplicate| duplicate.slug = nil if duplicate.respond_to?("slug=") }
end
friendly_id() click to toggle source

Get the instance's friendly_id.

# File lib/friendly_id/base.rb, line 255
def friendly_id
  send friendly_id_config.query_field
end
friendly_id_config() click to toggle source

Convenience method for accessing the class method of the same name.

# File lib/friendly_id/base.rb, line 250
def friendly_id_config
  self.class.friendly_id_config
end
to_param() click to toggle source

Either the friendly_id, or the numeric id cast to a string.

Calls superclass method
# File lib/friendly_id/base.rb, line 260
def to_param
  if friendly_id_config.routes == :friendly
    friendly_id.presence.to_param || super
  else
    super
  end
end