module FriendlyId::ActiveRecord2::SluggedModel

Public Class Methods

included(base) click to toggle source
# File lib/friendly_id/active_record2/slugged_model.rb, line 216
def self.included(base)
  base.class_eval do
    has_many :slugs, :order => 'id DESC', :as => :sluggable, :dependent => :destroy
    before_save :build_slug
    after_save :set_slug_cache
    after_update :update_scope
    after_update :update_dependent_scopes
    protect_friendly_id_attributes
    extend FinderMethods
  end
end

Public Instance Methods

find_slug(name, sequence) click to toggle source
# File lib/friendly_id/active_record2/slugged_model.rb, line 231
def find_slug(name, sequence)
  slugs.find_by_name_and_sequence(name, sequence)
end
slug() click to toggle source

The model instance's current {FriendlyId::ActiveRecord2::Slug slug}.

# File lib/friendly_id/active_record2/slugged_model.rb, line 236
def slug
  return @slug if new_record?
  @slug ||= slugs.first(:order => "id DESC")
end
slug=(slug) click to toggle source

Set the slug.

Calls superclass method
# File lib/friendly_id/active_record2/slugged_model.rb, line 242
def slug=(slug)
  @new_friendly_id = slug.to_friendly_id unless slug.nil?
  super
end
to_param() click to toggle source

Returns the friendly id, or if none is available, the numeric id.

# File lib/friendly_id/active_record2/slugged_model.rb, line 248
def to_param
  friendly_id_config.cache_column ? to_param_from_cache : to_param_from_slug
end