123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Timestamps::Created

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ActiveSupport::Concern
Defined in: lib/mongoid/timestamps/created.rb,
lib/mongoid/timestamps/created/short.rb

Overview

This module handles the behavior for setting up document created at timestamp.

Instance Method Summary

DSL Calls

included

[ GitHub ]


13
14
15
16
17
18
# File 'lib/mongoid/timestamps/created.rb', line 13

included do
  include Mongoid::Timestamps::Timeless

  field :created_at, type: Time
  set_callback :create, :before, :set_created_at
end

Instance Method Details

#set_created_at

Update the created_at field on the ::Mongoid::Document to the current time. This is only called on create.

Examples:

::Set the created at time.

person.set_created_at
[ GitHub ]

  
# File 'lib/mongoid/timestamps/created.rb', line 25

def set_created_at
  if !timeless? && !created_at
    now = Time.current
    self.updated_at = now if is_a?(Updated) && !updated_at_changed?
    self.created_at = now
  end
  clear_timeless_option
end