Storing User Data
Before users can do any of that, though, Rails needs a table for storing their data. The generator created a migration file in db/migrate, with a name ending in create_users, shown in Example 14-1.
Example 14-1. The migration for creating users in the database
class CreateUsers < ActiveRecord::Migration
def self.up
create_table "users", :force => true do |t|
t.column :login, :string
t.column :email, :string
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
t.column :remember_token_expires_at, :datetime
end
end
def self.down
drop_table "users"
end
endThere’s no pressing need to change this, but if you know you have
plans for additional fields about your users, you could add additional
columns. (This migration uses the older t.column syntax rather than the newer t.datatype syntax,
but it should still be clear what’s being created here.) To create the
table, run rake db:migrate.
Sessions don’t have a model or migrations—they’re just a controller that operates on users, so there isn’t anything more to do with them yet.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access