From 9a1b2b031c61a73b02dc71c396fa7dca503ec720 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Tue, 26 Sep 2023 12:24:21 -0500 Subject: [PATCH] Complete Lesson 23 --- app/controllers/reviews_controller.rb | 4 ++++ app/views/movies/show.html.erb | 3 +++ app/views/reviews/index.html.erb | 18 ++++++++++++++++++ config/routes.rb | 4 +++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 app/views/reviews/index.html.erb diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index b3d77cc..0c07f2c 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -1,2 +1,6 @@ class ReviewsController < ApplicationController + def index + @movie = Movie.find(params[:movie_id]) + @reviews = @movie.reviews + end end diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index d54d205..a321526 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -7,6 +7,9 @@

<%= year_of(@movie) %> • <%= @movie.rating %>

+
+ <%= link_to pluralize(@movie.reviews.size, "review"), movie_reviews_path(@movie) %> +

<%= @movie.description %>

diff --git a/app/views/reviews/index.html.erb b/app/views/reviews/index.html.erb new file mode 100644 index 0000000..95a8d44 --- /dev/null +++ b/app/views/reviews/index.html.erb @@ -0,0 +1,18 @@ +

Reviews for <%= link_to @movie.title, @movie %>

+ + diff --git a/config/routes.rb b/config/routes.rb index 7b6f8ff..97916af 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,5 +2,7 @@ Rails.application.routes.draw do resources :reviews root "movies#index" - resources :movies + resources :movies do + resources :reviews + end end