Date null when saving model

Hi,
I must be doing something dumb, but I can’t figure this out.

The following code:

customer = Customer.new(:name => ‘Ray’, :date_created =>
Time.now.to_s(:db))
customer.save!

Always results in the error ActiveRecord::RecordInvalid: Validation
failed: Date created can’t be null

Yet, this code works fine:
customer = Customer.new(:name => ‘Ray’)
customer.date_created = Time.now.to_s(:db)
customer.save!

Is there something I’m doing wrong that is preventing me from putting
everything in the new method?
Any help would be appreciated.
Cheers,
Ray

Raymond O’Connor wrote:

failed: Date created can’t be null

Yet, this code works fine:
customer = Customer.new(:name => ‘Ray’)
customer.date_created = Time.now.to_s(:db)
customer.save!

Is there something I’m doing wrong that is preventing me from putting
everything in the new method?

Have you excluded date_created from mass updates via attr_accessible
or attr_protected? If so, the second method is the only way that
currently works, however I’d like to see new_unsafe, create_unsafe,
build_unsafe, attributes_unsafe=, and update_attributes_unsafe methods
that bypass protection for use in internal processing.

The other alternative is some problem with your Customer.initialize
code.


We develop, watch us RoR, in numbers too big to ignore.

Raymond O’Connor wrote:

Hi,
I must be doing something dumb, but I can’t figure this out.

The following code:

customer = Customer.new(:name => ‘Ray’, :date_created =>

Remember you can use “created_at” which will insert the date for you
automatic :slight_smile: