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:
In this step we'll learn a bit about MVC (Model-View-Controller) architecture. By the end of this step you should understand the following concepts:
Try the following in your terminal:
$ rails generate scaffold topic title:string description:text $ rake db:migrate $ rails server
If you want, take some time to poke around the files listed in the generate step.
rails generate scaffold topic title:string description:text
generate scaffoldtells rails to create everything necessary to get up and running with topics
topictells rails the name of the new model
title:stringsays that topics have a title, which is a string.
description:textsays that topics have a description which is a "text". (We're befuddled by the difference too).
rake db:migratetells rails to update the database to include a table for our new model
Rails implements a very specific notion of the Model View Controller pattern, which guides how you structure your web applications.
In MVC, models, views, and controllers have very specific jobs. Separating responsibilities like this make it easy to maintain and extend rails applications. When responsibilities become muddied it gets much harder to debug issues and add new functionality.