Terminal

Code Editor
Web Browser
Learn
Saving Data

Controller

What did we just do?

1. The rails generate model command created a new model named Message. In doing so, Rails created two files:

  1. a model file in app/models/message.rb. The model represents a table in the database.
  2. a migration file in db/migrate/. Migrations are a way to update the database.

2. Open the migration file in db/migrate/. The migration file contains a few things:

  1. The change method tells Rails what change to make to the database. Here it uses the create_table method to create a new table in the database for storing messages.
  2. Inside create_table, we added t.text :content. This will create a text column called content in the messages tables.
  3. The final line t.timestamps is a Rails command that creates two more columns in the messages table called created_at and updated_at. These columns are automatically set when a message is created and updated.

3. The rake db:migrate command updates the database with the new messages data model.

4. Finally the rake db:seed command seeds the database with sample data from db/seeds.rb.

Report a Bug
If you see a bug or any other issue with this page, please report it here.