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

+ (Object) included(base)



6
7
8
9
10
11
12
13
14
# 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
  end
end

Instance Method Details

- (Object) friendly_id Also known as: best_id

Returns the friendly_id.



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

def friendly_id
  send friendly_id_config.column
end

- (Object) friendly_id_status

Get the Status after the find has been performed.



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

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

- (Object) to_param

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



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

def to_param
  (friendly_id || id).to_s
end