jos*_*im5 1 ruby database migration ruby-on-rails ruby-on-rails-3
我已经看到了两种不同的迁移数据库的方法.在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
Run Code Online (Sandbox Code Playgroud)
谢谢!
t.string :title
只是一个捷径 t.column :title, :string
两者都没问题,没有歧视.我通常更喜欢简短形式,因为它对我来说更具可读性,但这只是一个意见问题.