{"id":598,"date":"2008-12-14T11:22:46","date_gmt":"2008-12-14T19:22:46","guid":{"rendered":"https:\/\/www.ultrasaurus.com\/sarahblog\/2008\/12\/getting-started-with-rails-2-day-2\/"},"modified":"2008-12-14T11:22:46","modified_gmt":"2008-12-14T19:22:46","slug":"getting-started-with-rails-2-day-2","status":"publish","type":"post","link":"https:\/\/www.ultrasaurus.com\/2008\/12\/getting-started-with-rails-2-day-2\/","title":{"rendered":"getting started with rails 2 – day 2"},"content":{"rendered":"

In Day 1<\/a> with Rails, we built a simple application that let us manage a list of categories using the powerful generate scaffold script. Today, we’ll look under the hood and learn about the code that was created for us, so that we can modify the application to do just what we want (or, rather, what the tutorial Four Days on Rails<\/a> tutorial did, as I continue to update that tutorial for Rails 2.)<\/p>\n

You’ll get the most out of Day 2, if you already know Ruby or you first read chapters 0-3 of the humble little Ruby book<\/a> or some other introduction to the language. Or, of course, you can just wing it.<\/p>\n

You also should know about the MVC (Model View Controller) design pattern. Although if you don’t know MVC already, you’ll get the hang of it soon, at least from the Rails perspective. The Getting Started Guide has a nice intro<\/a> to MVC and elaborates on how Rails applies this venerated pattern:<\/p>\n

\n

2.1.1. Models<\/strong> A model represents the information (data) of the application and the rules to manipulate that data. In the case of Rails, models are primarily used for managing the rules of interaction with a corresponding database table. In most cases, one table in your database will correspond to one model in your application. The bulk of your application’s business logic will be concentrated in the models.<\/p>\n

2.1.2. Views<\/strong> Views represent the user interface of your application. In Rails, views are often HTML files with embedded Ruby code that performs tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application.<\/p>\n

2.1.3. Controllers<\/strong> Controllers provide the “glue” between models and views. In Rails, controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation.<\/p>\n<\/blockquote>\n

In today’s tutorial, we will learn about:<\/p>\n

    \n
  1. The Model<\/a>\n