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

+ (Object) included(base)



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

def self.included(base)
  base.class_eval do
    has_one :slug, :order => 'id DESC', :as => :sluggable, :dependent => :nullify
    has_many :slugs, :order => 'id DESC', :as => :sluggable, :dependent => :destroy
    before_save :build_a_slug
    after_save :set_slug_cache
    after_update :update_scope
    after_update :update_dependent_scopes
    protect_friendly_id_attributes

    def slug_with_rails_3_2_patch
      slug_without_rails_3_2_patch || slugs.first
    end

    alias_method_chain :slug, :rails_3_2_patch
  end
end

Instance Method Details

- (Object) find_slug(name, sequence)



25
26
27
# File 'lib/friendly_id/active_record_adapter/slugged_model.rb', line 25

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

- (Object) to_param

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.



31
32
33
# File 'lib/friendly_id/active_record_adapter/slugged_model.rb', line 31

def to_param
  friendly_id_config.cache_column ? to_param_from_cache : to_param_from_slug
end