Module: FriendlyId::ActiveRecordAdapter::SimpleModel

Defined in:
lib/friendly_id/active_record_adapter/simple_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

def self.included(base)
  base.class_eval do
    column = friendly_id_config.column
    validate :validate_friendly_id, :unless => :skip_friendly_id_validations
    validates_presence_of column, :unless => :skip_friendly_id_validations
    validates_length_of column, :maximum => friendly_id_config.max_length, :unless => :skip_friendly_id_validations
    after_update :update_scopes
    extend FriendlyId::ActiveRecordAdapter::Finders unless FriendlyId.on_ar3?
  end
end

Instance Method Details

#friendly_idObject Also known as: best_id

Returns the friendly_id.



23
24
25
# File 'lib/friendly_id/active_record_adapter/simple_model.rb', line 23

def friendly_id
  send friendly_id_config.column
end

#friendly_id_statusObject

Get the Status after the find has been performed.



18
19
20
# File 'lib/friendly_id/active_record_adapter/simple_model.rb', line 18

def friendly_id_status
  @friendly_id_status ||= Status.new :record => self
end

#to_paramObject

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



29
30
31
# File 'lib/friendly_id/active_record_adapter/simple_model.rb', line 29

def to_param
  (friendly_id || id).to_s
end