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 added the line t.references :tag to the destinations table. This adds a foreign key pointing to the tags table.
  4. 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 Tags


In the routes file, add a new route that maps requests to /tags to the Tags controller’s index action.


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.


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.


Visit http://localhost:8000/tags in the browser.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?