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 routeget '/tags/:id' => 'tags#show'
sends this request to the Tags controller’s show action with{id: 1}
inparams
. - The
@destinations = @tag.destinations
retrieves all the destinations that belong to the tag, and stores them in@destinations
. Thehas_many
/belongs_to
association lets us query for destinations like this. - The tag and its destinations are sent to the view to be displayed.
Instructions
Let’s add functionality to see a destination.
Generate a controller named Destinations.
Next in the routes file, map requests to/destinations/:id
to the Destinations controller’s show
action. Use as:
to name this route “destination”.
Then in the Destinations controller, set up the show
action. Use params
to find a destination by id, and save it in @destination
Then in the view app/views/destinations/show.html.erb, display the destination’s image, name, and description.
Finally in app/views/tags/show.html.erb below a destination’s description, use link_to
to add a link to that destination:
- Use “See more” for the link text
- By giving the
show
route a name of “destination”, Rails automatically creates a helper method nameddestination_path
. Usedestination_path
to generate a URL to a specific destination’s path.
Visit http://localhost:8000/tags/1
in the browser. Click on a destination to see its show page.