Posts tagged as:

migrations

Rails 2.0 Timestamps

February 19, 2008

No Gravatar

Thought timestamps were easy before? Timestamps in Rails 2.0 are super easy.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# before
class CreateUsers < ActiveRecord::Migration
 def self.up
 create_table :users do |t|
 t.column :name, :string
 t.column :subscribed, :boolean, :default => true
 t.column :created_on, :timestamp
 t.column :updated_on, :timestamp
 end
 end
 
 def self.down
 drop_table :users
 end
end
 
# after
class CreateUsers < ActiveRecord::Migration
 def self.up
 create_table :users do |t|
 t.string :name
 t.boolean :subscribed, :default => true
 t.timestamps
 end
 end
 
 def self.down
 drop_table :users
 end
end

{ View Comments }