Thought timestamps were easy before? Timestamps in Rails 2.0 are super easy.
# 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
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
Tags: 2.0, edge, migrations, rails
Nice website. What do you use to color code the ruby, syntax?
On the ‘t.timestamps’, I thought it was singular, t.timestamp. And if you do ‘rake db:schema:dump’, it comes out t.datetime. I think it’s the same thing.
Nice website. What do you use to color code the ruby, syntax?
On the ‘t.timestamps’, I thought it was singular, t.timestamp. And if you do ‘rake db:schema:dump’, it comes out t.datetime. I think it’s the same thing.
The timestamp columns created are actually ‘created_at’ and ‘updated_at’, both datetime fields. The suffix ‘_on’ denotes a date field, and the suffix ‘_at’ denotes a datetime field. Thanks for the blog!
The timestamp columns created are actually ‘created_at’ and ‘updated_at’, both datetime fields. The suffix ‘_on’ denotes a date field, and the suffix ‘_at’ denotes a datetime field. Thanks for the blog!