Hey everyone, I'm in a little situation.
So, I'm making this shoutbox with ruby, and I want a way to easily display the time of the post by the users.. so I used timestamp.
Heres the table I used:
sqlite> create table shouts
...> (id INT NOT NULL ,
...> postdate timestamp(14) ,
...> name VARCHAR( 20 ) NOT NULL ,
...> description VARCHAR( 200 ) NOT NULL ,
...> PRIMARY KEY ( id )
...> );
In my application controller, I have the scaffold method. When I try to create new entries, I get this error:
shouts.id may not be NULL: INSERT INTO shouts ('name', 'postdate', 'description') VALUES('adf', NULL, 'adf')
Is there a simple way to fix this? Thank you for your time.
Apparently that's not it either. It is auto incremented and it still ins't working.. THe value NULL keep being put in for timestamp. Hmm... Anyone ever setup a timestamp with SQLite3?
Last edited by Sniph; Dec 14, 2005 at 13:13.
Reason: .
make your timestamp columns in your database called:
created_at and updated_at
if you name your columns like this then rails will fill in the timestamps for free. Make the columns of type datetime or even if they are just strings like most sqlite columns, rails will fill in the created_at with the daettime stamp of when the object was first created. And updated_at will be updated every time the object is updated.
You will get errors with time and dates when you don't initialize the attributes in your ActiveRecord object. Because rails automatically handles created_on and updated_on, it is recommended you use these names for this very reason as ezmobius1 said.
Bookmarks