Nice work. What did we just do?
- We added two string columns
imageto the tags table
- We added three string columns
descriptionto the destinations table
- We also added the line
t.references :tagto 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.
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
In the routes file, add a new route that maps requests to
/tags to the Tags controller’s
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
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.
http://localhost:8000/tags in the browser.