Nice work. What did we just do?
imageto the tags table
descriptionto the destinations table
t.references :tagto the destinations table. This adds a foreign key pointing to the tags table.
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.