I think created_at
is always set to the time a record created in by ActiveRecord, but I found some records are created with null created_at
.
Are there any condition to cause this?
These columns created_at, updated_at, created_on, updated_on are automatically handled for you by rails.
However, there are a few notes:
created_at
should be nil before create and shouldn't be changed before update). Otherwise, ActiveRecord won't update attr's value with the current time.<ClassName>.record_timestamps
is set to true.Also, I'd suggest to you to add not-null constraint to these columns:
change_column :<table_name>, :created_at, :datetime, :null => false
This way you will be sure that this column always have a not-null value.
Are you using attr_accessible
or attr_protected
on your model?
Because without those basic protections, any update request could be setting these otherwise unvalidated & unprotected attributes.
Mass-assignment security
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With