Ruby On Rails Migration
I have seen two different ways of migrating a database. Which one is the proper way to do it in Rails 3?
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.string :title
t.timestamps
end
end
and
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.开发者_高级运维column :name, :string
t.timestamps
end
end
Thank You!
t.string :title
is just a shortcut for t.column :title, :string
Both of them are ok, there is no discrimination. I'd normally prefer the short form, as it is more readable to me but it's just a matter of opinion.
精彩评论