Module: FriendlyId::Model

Defined in:
lib/friendly_id/base.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model_class) ⇒ Object


247
248
249
# File 'lib/friendly_id/base.rb', line 247

def self.included(model_class)
  return if model_class.respond_to?(:friendly)
end

Instance Method Details

#dupObject

Clears slug on duplicate records when calling dup.


271
272
273
# File 'lib/friendly_id/base.rb', line 271

def dup
  super.tap { |duplicate| duplicate.slug = nil if duplicate.respond_to?('slug=') }
end

#friendly_idObject

Get the instance's friendly_id.


257
258
259
# File 'lib/friendly_id/base.rb', line 257

def friendly_id
  send friendly_id_config.query_field
end

#friendly_id_configObject

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


252
253
254
# File 'lib/friendly_id/base.rb', line 252

def friendly_id_config
  self.class.friendly_id_config
end

#to_paramObject

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


262
263
264
265
266
267
268
# File 'lib/friendly_id/base.rb', line 262

def to_param
  if friendly_id_config.routes == :friendly
    friendly_id.presence.to_param || super
  else
    super
  end
end