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)
-
- (Object) dup
Clears slug on duplicate records when calling
dup
. -
- (Object) friendly_id
Get the instance's friendly_id.
-
- (Object) friendly_id_config
Convenience method for accessing the class method of the same name.
-
- (Object) to_param
Either the friendly_id, or the numeric id cast to a string.
Class Method Details
+ (Object) included(model_class)
231 232 233 |
# File 'lib/friendly_id/base.rb', line 231 def self.included(model_class) return if model_class.respond_to?(:friendly) end |
Instance Method Details
- (Object) dup
Clears slug on duplicate records when calling dup
.
255 256 257 |
# File 'lib/friendly_id/base.rb', line 255 def dup super.tap { |duplicate| duplicate.slug = nil if duplicate.respond_to?('slug=') } end |
- (Object) friendly_id
Get the instance's friendly_id.
241 242 243 |
# File 'lib/friendly_id/base.rb', line 241 def friendly_id send friendly_id_config.query_field end |
- (Object) friendly_id_config
Convenience method for accessing the class method of the same name.
236 237 238 |
# File 'lib/friendly_id/base.rb', line 236 def friendly_id_config self.class.friendly_id_config end |
- (Object) to_param
Either the friendly_id, or the numeric id cast to a string.
246 247 248 249 250 251 252 |
# File 'lib/friendly_id/base.rb', line 246 def to_param if diff = changes[friendly_id_config.query_field] diff.first || diff.second else friendly_id.presence.to_param || super end end |