What did we just do?
rails generate model command created a new model named Message. In doing so, Rails created two files:
- a model file in app/models/message.rb. The model represents a table in the database.
- 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:
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.
create_table, we added
t.text :content. This will create a text column called
content in the messages tables.
- The final line
t.timestamps is a Rails command that creates two more columns in the messages table called
updated_at. These columns are automatically set when a message is created and updated.
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.