Associations I
Lesson 1 of 1
  1. 1
    We built a Rails app that stores data using a single model. What if we want to build an app with more than one kind of data, like Team and Athlete? Both Team and Athlete would have have different …
  2. 2
    Great! Looking at the request/response cycle, we need four parts to build the travel app: models, controllers, routes, and views. Let’s begin by creating the models.
  3. 3
    What did we just do? We created two models named Tag and Destinations. Then, in the model files, we used the methods has_many and belongs_to to define an association between Tag and Destination. …
  4. 4
    Nice work. What did we just do? 1. We added two string columns title and image to the tags table 2. We added three string columns name, image, and description to the destinations table 3. We also …
  5. 5
    Well done! The app now displays a list of tags from the database.
  6. 6
    Nice job! The app displays all destinations that belong to a tag. How does this work? - When a user visits http://localhost:8000/tags/1, the route get ‘/tags/:id’ => ‘tags#show’ sends this request…
  7. 7
    Great! The app now displays a specific destination. Let’s continue by adding actions to update a destination’s name and description. Looking at the seven standard Rails actions, we need to use the…
  8. 8
    Nicely done! You can now update a destination’s name and description. How does it work? When you visit http://localhost:8000/destinations/1/edit to edit a destination, it triggers the first turn o…
  9. 9
    Congratulations! You built an travel app that uses a database to store two kinds of data. What can we generalize so far? - We connected a Tag to its Destinations using associations. In this case…

What you'll create

Portfolio projects that showcase your new skills

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory