Topic: Model Schema Conventions

I've looked a few tutorials and have noticed some variations in the way the schema can be written.

001_create_users.rb  -- 1st code sample. Note that field name is preceded by a colon.

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      # t.column :name, :string
      t.column  :username,      :string
      t.column  :password_salt, :string
      t.column  :password_hash, :string
    end
  end

  def self.down
    drop_table :users
  end
end

================================

001_create_users.rb  -- 2nd code sample. This time field names are wrapped in quotes.

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.column  "username",      :string
      t.column  "password_salt", :string
      t.column  "password_hash", :string
    end
  end

  def self.down
    drop_table :users
  end
end

I normally do the 1st version as this is what Rails books have had however a recent example in Rails recipes had the second version.  Does it matter?

Re: Model Schema Conventions

As far as database migrations there's no difference between the two.  It's purely a style decision.

The things with the colons in front are called 'symbols'.  They're not common in other languages but you can think of them as the diet version of strings.  They consume less memory, they have fewer methods attached to them, and (most importantly) they look pretty cool.  You'll find a lot of places in Rails where either strings or symbols work just fine.