Ruby on Rails/ActiveRecord/Timestamps

From Wikibooks, open books for an open world
< Ruby on Rails‎ | ActiveRecord
Jump to navigation Jump to search

Active Record automatically timestamps during create and update operations if the table has fields created_at/created_on or updated_at/updated_on. This can be disabled on individual models by setting @self.record_timestamps = false@ in the class definition for the model. For example:

   class SomeModel < ActiveRecord::Base
     self.record_timestamps = false

Although there is no explicit requirement, typically the _on fields should be date types, whereas the _at fields should be datetime types.

Timestamps are in the local timezone by default but can use UTC by setting ActiveRecord::Base.default_timezone = :utc. This will normally be specified in config/environment.rb.

Source: active_record/timestamp.rb