Forum: Ruby on Rails How to use Time type in rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zhao Y. (Guest)
on 2009-01-22 03:44
I defines a table and one of its column type is Time. I use ruby Time
class to assign the value to this column, but it always generate Sat Jan
01 2000 time. Is the format different with the database and ruby class?
I use MySql database in Linux.
Bobnation (Guest)
on 2009-01-22 06:42
(Received via mailing list)
Are you using Time.now to assign the time?
Zhao Y. (Guest)
on 2009-01-22 06:45
Bobnation wrote:
> Are you using Time.now to assign the time?

Yes, I use Time.now.
Bobnation (Guest)
on 2009-01-22 08:09
(Received via mailing list)
Can you post your schema.rb?
Zhao Y. (Guest)
on 2009-01-22 09:01
Bobnation wrote:
> Can you post your schema.rb?

This is schema file:

class CreateHistories < ActiveRecord::Migration
  def self.up
    create_table :histories do |t|
      t.string :user_name,:null=>false
      t.string :project_name,:null=>false
      t.string :view
      t.string :task
      t.date :date
      t.time :time
      t.string :log

      t.timestamps
    end
  end

  def self.down
    drop_table :histories
  end
end
jasoo24 (Guest)
on 2009-01-24 01:16
(Received via mailing list)
Do created_at and updated_at (via t.timestamps) get set properly? I
think you could try using t.timestamp (not plural) instead of t.time.

Or, instead of using "sexy migrations", you could try doing it the old
way:
t.column :my_time_column, :datetime

Hope this helps,
Jason Arora
Zhao Y. (Guest)
on 2009-01-24 02:34
jasoo24 wrote:
> Do created_at and updated_at (via t.timestamps) get set properly? I
> think you could try using t.timestamp (not plural) instead of t.time.
>
> Or, instead of using "sexy migrations", you could try doing it the old
> way:
> t.column :my_time_column, :datetime
>
> Hope this helps,
> Jason Arora


How can I migrate this schema without breaking this table? I have tried
to run "rake db:migrate" but it doesn't work.
This topic is locked and can not be replied to.