[MUSIC] Let's start by talking at a high level about how data flows through a Web application. I'll talk about how Rails sets things up for you automatically to manage data, which by the way is very similar to how many modern Web application frameworks work. Let's consider the three-tier architectural view of a Web application. Recall that this consists of a Web Client tier, which is the browser, the Application tier, which is the Web application, and the Data tier. That is, the data sources that the Web application will use. What type of data is used within each of these tiers? Well, on the client side, your browser knows how to render HTML, so ultimately the Web server must supply data formatted for display using HTML. The Web app itself, well, it's based on an object-oriented programming language, so the data in this tier is stored in objects. The data sources are often referred to as the persistence layer. That's because this tier is often used to persist data, and what I mean by this is that it's used to store data that persists from one Web session to the next. Now relational databases are commonly used for this purpose, and they consist of tables that hold records, which consist of fields. We've already mentioned that the protocol for passing data between the Web client and the Web app is HTTP. Data is often collected using a Web form on the client side and then passed using HTTP to the Web server. In addition, data is often passed back and forth between the client and the server using JSON, which stands for JavaScript Object Notation. We'll learn more about this later. Now in order to store or retrieve data from a relational database, you must perform SQL queries, which by the way stands for Structured Query Language. Now there's a fundamental problem here. There's a mismatch between the data stored in objects on the Web App side and how it's stored in tables on the database side. The Active Record Design Pattern was created to address this problem. It provides an abstraction that allows you to think object-oriented, even though you're using a relational database on the back end. It does this by encapsulating the SQL queries within the design pattern, so you dont have to directly use SQL queries in your Web App to access the database. How does this all come together in Rails? Well, code generators, which is what you used when you executed the rails generate scaffold commands, are used to automatically create the classes and objects you need on the Web App side as well as the migrations needed on the database side. When you run rake db.migrate, a database schema is created, and this is used to construct the relational database. Again, all of this is done in such a way that the Active Record Design Pattern is instantiated across these two tiers.