SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member Sniph's Avatar
    Join Date
    Dec 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question RoR timestamp/sql Help :)

    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.

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Is your id column an autoincrement column? If it isn't then that is probably your problem.

  3. #3
    SitePoint Member Sniph's Avatar
    Join Date
    Dec 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ..

    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 12:13. Reason: .

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Yakima WA.
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sniph-

    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.

  5. #5
    Resident Java Hater
    Join Date
    Jul 2004
    Location
    Gerodieville Central, UK
    Posts
    446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •