Complete Lesson 23

main
Simon Quigley 1 year ago
parent 71220cd85f
commit 9a1b2b031c

@ -1,2 +1,6 @@
class ReviewsController < ApplicationController
def index
@movie = Movie.find(params[:movie_id])
@reviews = @movie.reviews
end
end

@ -7,6 +7,9 @@
<h2>
<%= year_of(@movie) %> &bull; <%= @movie.rating %>
</h2>
<div class="reviews">
<%= link_to pluralize(@movie.reviews.size, "review"), movie_reviews_path(@movie) %>
</div>
<p>
<%= @movie.description %>
</p>

@ -0,0 +1,18 @@
<h1>Reviews for <%= link_to @movie.title, @movie %></h1>
<ul class="reviews">
<% @reviews.each do |review| %>
<li>
<%= pluralize(review.stars, 'star') %>
<p>
<%= review.name %>
<span class="date">
<%= time_ago_in_words(review.created_at) %> ago
</span>
</p>
<p>
<%= review.comment %>
</p>
</li>
<% end %>
</ul>

@ -2,5 +2,7 @@ Rails.application.routes.draw do
resources :reviews
root "movies#index"
resources :movies
resources :movies do
resources :reviews
end
end

Loading…
Cancel
Save