joshim5
joshim5

Reputation: 2255

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!

Upvotes: 1

Views: 246

Answers (1)

edgerunner
edgerunner

Reputation: 14973

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.

Upvotes: 5

Related Questions