# Created\_on not working

**URL:** <https://www.ruby-forum.com/t/created-on-not-working/76502>\
**Category:** Rails\
**Created:** [November 19, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/created-on-not-working/76502 "2006-11-19T18:58:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [November 19, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/created-on-not-working/76502/1 "2006-11-19T18:58:39Z")

</div>

CREATE TABLE jobs (  
id integer primary key auto\_increment,  
username varchar(255),  
email int(4) NOT NULL default 1,  
renderer varchar(2) NOT NULL default ‘HW’,  
version varchar(8) NOT NULL default ‘8.0’,  
job\_name varchar(255) NOT NULL default ‘’,  
number\_of\_frames\_per\_task int(10) NOT NULL default ‘0’,  
total\_number\_of\_frames int(11) NOT NULL default ‘0’,  
STATE tinyint(3) unsigned NOT NULL default ‘0’,  
created\_on timestamp,  
updated\_on timestamp,  
index(id)  
) ENGINE=InnoDB

ruby script/generate model job  
ruby script/generate controller student  
ruby script/generate scaffold job student

[http://localhost/.../student/new](http://localhost/.../student/new) has entries for created\_on and  
updated\_on. I’d like these to be handled automatically. According to  
the docs I’ve found, this should work. I tried it with the time  
‘datetime’ instead of timestamp as stated by one doc, but it did not  
change anything.

Thank you.

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [November 19, 2006, 7:37pm UTC](https://www.ruby-forum.com/t/created-on-not-working/76502/2 "2006-11-19T19:37:07Z")

</div>

Jonathan D. wrote:

> created\_on timestamp,  
> updated\_on timestamp,  
> index(id)  
> ) ENGINE=InnoDB  
> [http://localhost/.../student/new](http://localhost/.../student/new) has entries for created\_on  
> and updated\_on. I’d like these to be handled automatically.

I know that Rails will automatically update a field called ‘updated\_at’  
if  
you’re using AR for session management. I’ve copied in my script below.  
I  
haven’t used ‘created\_at’ but I believe that works the same way. I’m  
using  
MySQL. I don’t know whether or not that’s a requirement.

hth,  
Bill

create table sessions (  
id int not null  
auto\_increment,  
sessid varchar(255),  
data text,  
updated\_at datetime default NULL,  
primary key(id),  
index session\_index (sessid)  
) engine=InnoDB;

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [November 20, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/created-on-not-working/76502/3 "2006-11-20T14:45:39Z")

</div>

On 11/19/06, Jonathan D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> total\_number\_of\_frames int(11) NOT NULL default ‘0’,  
> [http://localhost/.../student/new](http://localhost/.../student/new) has entries for created\_on and  
> updated\_on. I’d like these to be handled automatically. According to  
> the docs I’ve found, this should work. I tried it with the time  
> ‘datetime’ instead of timestamp as stated by one doc, but it did not  
> change anything.

The scaffold generator doesn’t know about the magic nature of these  
fields -  
they will be filled in automatically, so you can go ahead and delete  
them  
from  
the \_form partial.

–  
Matt J.  
removed\_email\_address@domain.invalid  
President/Technical Director, Acme Art Company ([acmeartco.org](http://acmeartco.org))

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [November 20, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/created-on-not-working/76502/4 "2006-11-20T14:45:41Z")

</div>

On Sun, Nov 19, 2006 at 06:58:39PM +0100, Jonathan D. wrote:

> STATE tinyint(3) unsigned NOT NULL default ‘0’,  
> created\_on timestamp,  
> updated\_on timestamp,  
> index(id)  
> ) ENGINE=InnoDB

I’m not sure if this is the problem but created\_on/updated\_on are for  
dates, whereas created\_at/updated\_at are for timestamps. Try renaming  
the columns and see if it helps. Otherwise the logfiles may show what’s  
going on.

–  
Cheers,

- Jacob A.

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [November 21, 2006, 11:12pm UTC](https://www.ruby-forum.com/t/created-on-not-working/76502/5 "2006-11-21T23:12:19Z")

</div>

> The scaffold generator doesn’t know about the magic nature of these  
> fields -  
> they will be filled in automatically, so you can go ahead and delete  
> them  
> from  
> the \_form partial.

A cookie to Matt J… Thank you!

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [November 22, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/created-on-not-working/76502/6 "2006-11-22T16:51:57Z")

</div>

also,

i think its supposed to be  
created\_on date  
created\_at datetime

If this is mysql we’re talking about, if not, then nm

–jake

Jonathan D. wrote:

> > The scaffold generator doesn’t know about the magic nature of these  
> > fields -  
> > they will be filled in automatically, so you can go ahead and delete  
> > them  
> > from  
> > the \_form partial.
> 
> A cookie to Matt J… Thank you!
