goals {
model_diagram header: 'Topics', fields: %w(id title description)
message "The suggestotron has a list of topics that people can vote on. We'll store our topics in the database. In this step you'll do the following:"
goal "Create a simple *Table* in the database for topics with a title and a description"
goal "Automatically generate the corresponding *Scaffold* in Rails (namely, the *Model*, the *View*, and the *Controller*)."
}
steps {
step {
console "rails generate scaffold topic title:string description:text"
message <<-MARKDOWN
* `generate scaffold` tells Rails to create everything necessary to get up and running with topics.
* `topic` tells Rails the name of the new model.
* `title:string` says that topics have a title, which is a "string".
* `description:text` says that topics have a description which is a "text". (What's the difference between "string" and "text"? Basically "text" is for strings that might be very long.)
MARKDOWN
}
step {
console "rails db:migrate"
message "This tells Rails to update the database to include a table for our new model."
}
step {
message "Open `http://localhost:3000/topics` in the browser"
message "You should see an empty page with the heading 'Topics'"
}
}
explanation {
message <<-MARKDOWN
You used two `rails` commands in the terminal:
`rails generate` created files and folders for you. Here you used it to generate a scaffold consisting of model, a migration, a controller and some views.
`rails db:migrate` read the migration file (created by `rails generate`) and applied it to the database.
MARKDOWN
tip "You can run `rails --help` to see a list of all the `rails` commands your app currently responds to, along with a short description of each one."
}
commitnow do
message "find a good commit message and commit your changes"
end
next_step "rails_architecture"