Module: Devise::Models::Trackable

Defined in:
lib/devise/models/trackable.rb

Overview

Track information about your user sign in. It tracks the following columns:

  • sign_in_count - Increased every time a sign in is made (by form, openid, oauth)

  • current_sign_in_at - A timestamp updated when the user signs in

  • last_sign_in_at - Holds the timestamp of the previous sign in

  • current_sign_in_ip - The remote ip updated when the user sign in

  • last_sign_in_ip - Holds the remote ip of the previous sign in

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.required_fields(klass) ⇒ Object



14
15
16
# File 'lib/devise/models/trackable.rb', line 14

def self.required_fields(klass)
  [:current_sign_in_at, :current_sign_in_ip, :last_sign_in_at, :last_sign_in_ip, :sign_in_count]
end

Instance Method Details

#update_tracked_fields!(request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/devise/models/trackable.rb', line 18

def update_tracked_fields!(request)
  old_current, new_current = self., Time.now.utc
  self.     = old_current || new_current
  self.  = new_current

  old_current, new_current = self., request.remote_ip
  self.     = old_current || new_current
  self.  = new_current

  self. ||= 0
  self. += 1

  save(:validate => false) or raise "Devise trackable could not save #{inspect}." \
    "Please make sure a model using trackable can be saved at sign in."
end