Reputation: 365
In Rails, is there an automatically instantiated field that has this information, or would I have to create a separate column in the model to keep track of it?
Upvotes: 1
Views: 670
Reputation: 719
If you have columns called created_at
and updated_at
, they will update automatically. You can abbreviate that in your migration with t.timestamps
, which now shows up by default (or did last time I created a model). If you're talking about an object stored in the database, there's no information about it other than what's in the table.
On a side note, if you're talking about an instance of an ActiveRecord it's best to say "record" instead of "object." The latter refers to any object that you instantiate, be it a record that you retrieve or just a simple Foo.new
.
Upvotes: 4
Reputation: 3057
Rails automatically stores when each record is created in created_at
it also stores when the record was last updated in updated_at
Upvotes: 1