I’m starting to get involved with models in rails and so I need to make
sure I understand exactly what I’m trying to do. Let’s look at a quick
example:
One table that I will be creating is a rushing_offense table for
football. It has the following columns in the tables:
name (string)
games (fixnum)
carries (fixnum)
net (fixnum)
avg (float)
tds (fixnum)
ydspg (float)
wins (fixnum)
losses (fixnum)
ties (fixnum)
When I create the scaffold and setup the hash pairs the migration that
is created appears like this:
class CreateRushingOffenses < ActiveRecord::Migration
def self.up
create_table :rushing_offenses do |t|
t.string :name
t.fixnum :games
t.fixnum :carries
t.fixnum :net
t.float :avg
t.fixnum :tds
t.float :ydspg
t.fixnum :wins
t.fixnum :losses
t.fixnum :ties
t.timestamps
end
end
def self.down
drop_table :rushing_offenses
end
end
The question I have is regarding the column name. I’ve looked at some
other migration templates (namely those in the authentication system)
and for the users model/migration, it shows something along the lines
of:
class CreateUsers < ActiveRecord::Migration
def self.up
create_table “users”, :force => true do |t|
t.column :login, :string, :limit => 40
t.column :name, :string, :limit => 100,
:default => ‘’, :null => true
t.column :email, :string, :limit => 100
t.column :crypted_password, :string, :limit => 40
t.column :salt, :string, :limit => 40
t.column :created_at, :datetime
t.column :updated_at, :datetime
t.column :remember_token, :string, :limit => 40
t.column :remember_token_expires_at, :datetime
end
add_index :users, :login, :unique => true
end
def self.down
drop_table “users”
end
end
So, should my migration be showing t.column instead of t.type? I’m not
clear on the differences between this or how I would dictate with the
generator that a column should be forced (or even if it’s necessary).
Many thanks in advance.