2011-01-14 184 views
1

我看到了遷移數據庫的兩種不同方式。哪一個是在Rails 3中完成的正確方法?Ruby On Rails遷移

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 

謝謝!

+0

第一個是默認的,看你什麼時候搭腳手架 – apneadiving 2011-01-14 16:13:57

+0

那麼第二個是什麼優點呢? – joshim5 2011-01-14 16:26:08

回答

5

t.string :title只是爲t.column :title, :string

他們兩人都是OK的快捷方式,不存在歧視。我通常更喜歡簡短形式,因爲它對我來說更具可讀性,但這只是一個意見問題。