Module: FriendlyId::ActiveRecordAdapter::SluggedModel

Includes:
Slugged::Model
Defined in:
lib/friendly_id/active_record_adapter/slugged_model.rb

Instance Attribute Summary

Attributes included from Slugged::Model

#slug

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Slugged::Model

#friendly_id, #friendly_id_config, #friendly_id_status, #normalize_friendly_id, #slug?

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/friendly_id/active_record_adapter/slugged_model.rb', line 5

def self.included(base)
  base.class_eval do
    has_many :slugs, :order => 'id DESC', :as => :sluggable, :dependent => :destroy
    has_one :slug, :order => 'id DESC', :as => :sluggable, :dependent => :destroy,
            :conditions => (proc{ {:locale => Globalize.locale} } if friendly_id_config.class.locales_used?)
    before_save :build_a_slug
    after_save :set_slug_cache
    after_update :update_scope
    after_update :update_dependent_scopes
    protect_friendly_id_attributes
    extend FriendlyId::ActiveRecordAdapter::Finders unless FriendlyId.on_ar3?
  end
end

Instance Method Details

#find_slug(name, sequence) ⇒ Object



21
22
23
# File 'lib/friendly_id/active_record_adapter/slugged_model.rb', line 21

def find_slug(name, sequence)
  slugs.find_by_name_and_sequence(name, sequence)
end

#to_paramObject

Returns the friendly id, or if none is available, the numeric id. Note that this method will use the cached_slug value if present, unlike Slugged::Model#friendly_id.



27
28
29
# File 'lib/friendly_id/active_record_adapter/slugged_model.rb', line 27

def to_param
  friendly_id_config.cache_column ? to_param_from_cache : to_param_from_slug
end