Well done! The movies show up on the page.
Let’s add another action to display a specific movie and its actors. Looking at the seven standard controller actions, we need to use the
show action to do this.
In the routes file, add another route to send requests to URLs like
/movies/1 to the Movie controller’s
show action. Use
as: to name this route “movie”.
Then in the Movies controller, add the
show action to display a specific movie and its actors.
- First use
Movie.findto find the movie by its
- Then retrieve all actors that belong to the movie, and store them in
<div class="movie">...</div>, display the movie’s image, title, release year, and plot.
<h2>Cast</h2>, iterate through each actor and display the image, first name, last name, and bio.
Finally in app/views/movies/index.html.erb below a movie’s plot, use
link_to to add a link to that movie:
- Use “Learn more” for the link text
- By giving the
showroute a name of “movie”, Rails automatically creates a helper method named
movie_path, so use it to generate a URL to a specific movie’s path
http://localhost:8000/movies in the browser. Click on a ‘Learn more’ to see a movie and its actors.