How to use Time type in rails

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.

Are you using Time.now to assign the time?

Bobnation wrote:

Are you using Time.now to assign the time?

Yes, I use Time.now.

Can you post your schema.rb?

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 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.

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