Module: FriendlyId::Model

Defined in:
lib/friendly_id/base.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_friendly_idObject (readonly)

Returns the value of attribute current_friendly_id.



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

def current_friendly_id
  @current_friendly_id
end

Instance Method Details

#friendly_idObject

Get the instance’s friendly_id.



278
279
280
# File 'lib/friendly_id/base.rb', line 278

def friendly_id
  send friendly_id_config.query_field
end

#friendly_id_configObject

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



273
274
275
# File 'lib/friendly_id/base.rb', line 273

def friendly_id_config
  self.class.friendly_id_config
end

#to_paramObject

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



283
284
285
286
287
288
289
# File 'lib/friendly_id/base.rb', line 283

def to_param
  if diff = changes[friendly_id_config.query_field]
    diff.first || diff.second
  else
    friendly_id.presence || super
  end
end