Forum: Ruby on Rails created_on, created_at defaulting to 2000/01/01 00:00:00

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Peter F. (Guest)
on 2005-12-19 23:12
(Received via mailing list)
Hello all,

Rails 1.0.0
created_on is being set to 2000/01/01 00:00:00

Any ideas on this ?


Schema is
create table user_login_history (
id int identity(1,1) not null,
user_id int not null,
created_on datetime default(getdate()) not null,
created_at datetime default(getdate()) not null,
updated_on datetime default(getdate()) not null,
constraint pk_user_login_history primary key clustered (id),
constraint fk_user_login_history_users foreign key (user_id) references

ruby script/console
=> Mon Dec 19 14:39:53 Central Standard Time 2005
>> ulh ={:user_id=>1})
=> #<UserLoginHistory:0x3a0cde8 @attributes={"created_on"=>Sat Jan 01
00:00:00 Central Standard Time 2000, "updated_on"=
>Sat Jan 01 00:00:00 Central Standard Time 2000, "user_id"=>1,
"created_at"=>Sat Jan 01 00:00:00 Central Standard Time 2
000}, @new_record=true>
=> true
>> ulh
=> #<UserLoginHistory:0x3a0cde8 @attributes={"created_on"=>Sat Jan 01
00:00:00 Central Standard Time 2000, "updated_on"=
>Mon Dec 19 15:08:52 Central Standard Time 2005, "id"=>"4", "user_id"=>1,
"created_at"=>Sat Jan 01 00:00:00 Central Stan
dard Time 2000}, @errors=#<ActiveRecord::Errors:0x3a07a30 @errors={},
@base=#<UserLoginHistory:0x3a0cde8 ...>>, @new_rec

Alain R. (Guest)
on 2005-12-19 23:32

Why are you giving default values to those datetime fields? By default,
Rails automatically updates 'created_at' and 'updated_at', so you never
have to set them.

I would just remove the "default .." and see what happens.

Ed C. (Guest)
on 2005-12-19 23:42
(Received via mailing list)

First: you only need 1 "created" date/time field (named either
created_at OR
created_on) (the same rule applies to the "updated" date/time)

Second: can you show us your user login history model .rb code?

Peter F. (Guest)
on 2005-12-20 00:09
(Received via mailing list)
On 12/19/05, Ed C. <removed_email_address@domain.invalid> wrote:
> >
> > )
> > >>
> > >>
> >
HI Ed,

I actually solved this one.  Using defaults on the created_on/updated_on
fields short-circuits the "magic field names" functionality specified in

I removed teh default constraints from teh database and now the AR
are behaving as expected with magic field names.


This topic is locked and can not be replied to.