
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 scaffold tells rails to create everything necessary to get up and running with topicstopic tells rails the name of the new modeltitle:string says that topics have a title, which is a string.description:text says that topics have a description which is a "text". (We're befuddled by the difference too).rake db:migrate tells 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.
Model
View
Controller
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.