Learn
Nice work. What did we just do?
- We added two string columns
title
andimage
to the tags table - We added three string columns
name
,image
, anddescription
to the destinations table - We also added the line
t.references :tag
to the destinations table. This adds a foreign key pointing to the tags table. - Finally we ran the migrations to update the database, and seeded the database with the data in db/seeds.rb.
Instructions
1.
Now that the models are set up, let’s move on to the rest of the request/response cycle and create a controller, a route, and a view.
Generate a controller named Tags
2.
In the routes file, add a new route that maps requests to /tags
to the Tags controller’s index
action.
3.
Then in the Tags controller, add the index
action to display a list of all tags. To do this, fetch all tags from the database and store them in variable @tags
.
4.
In app/views/tags/index.html.erb at line 12, iterate through each tag in the @tags
array. Then for each tag, display its title and image.
We’ve provided CSS in app/assets/stylesheets/application.css.
5.
Visit http://localhost:8000/tags
in the browser.
Sign up to start coding
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.