Welcome to Lab 4! So far in the course, we've discussed routes, controllers, views, and —new today — models. Brief recap: What are models? They are a way we can structure data that our app needs to interact with. What are databases? They are a very organized way to save our data outside of the program files itself, and everything is represented in simple tables. Columns represent the attributes of a model, and rows represent a record or an instance of that model.

Students Table

Here's an example of what we're looking at! A table to represent student objects. All students have a first_name, a last_name and an age. As we create more students, we can just add more rows to the table! Let's dive into an example of how this will look in a Rails application.

rails-decal/fa19-lab4

Click the link above and fork the repo. You can now clone into your computer and cd.

git clone <https://github.com/your_username/fa19-lab4.git>
cd fa19-lab4
bundle install

The Next Amazon

In today's lab, we're going to build Jeff Bezos' worst nightmare: a competitor to Amazon. We'll provide you the base skeleton with routes, controllers, and some basic views. You'll be adding the functionality to help the app come alive. Instead of dealing with creating accounts and logging in and such, we're simply going to create a sort of admin dashboard where you can create sellers, create buyers, create products, and orchestrate purchases.

There's a lot of moving parts here, and it seems like a ton of functionality (it is!). But for one: this lab is here to guide you through it so that you can see how all these parts work. And two: as you'll soon be familiar with, Rails makes this process pretty painless! Finally, it'll hopefully be a little easier to get through these tasks when the UI is already built out for you 😊

Task 1: Brainstorming a schema and generating our models

So before we start building any web application with Rails, it's important to ask ourselves the question: What kind of data are we going to store? How do they relate? In this lab, we've answered the first question for you: we're storing Buyers, Sellers, Products, and Purchases. The question for you is: what properties do each of these need to have?

If you're doing this lab in class, brainstorm with your partner! Think about what kind of fields you want in each of our four models: Buyer, Seller, Product, Purchase. There's no right or wrong answer and you can customize your app for whatever fields you decide to include!