diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index d5b8e97..8be1a67 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -1,5 +1,6 @@ class ReviewsController < ApplicationController before_action :set_movie + before_action :require_signin def index @reviews = @movie.reviews @@ -9,6 +10,7 @@ class ReviewsController < ApplicationController end def create @review = @movie.reviews.new(review_params) + @review.user = current_user if @review.save redirect_to movie_reviews_path(@movie), notice: "Thanks for your review!" else @@ -23,6 +25,6 @@ class ReviewsController < ApplicationController end def review_params - params.require(:review).permit(:name, :stars, :comment) + params.require(:review).permit(:stars, :comment) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 943f385..8b34500 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -12,6 +12,7 @@ class UsersController < ApplicationController end def show + @reviews = @user.reviews end def create diff --git a/app/views/reviews/index.html.erb b/app/views/reviews/index.html.erb index 95a8d44..1ad0cc6 100644 --- a/app/views/reviews/index.html.erb +++ b/app/views/reviews/index.html.erb @@ -5,7 +5,7 @@
- <%= review.name %> + <%= link_to review.user.name, review.user %> <%= time_ago_in_words(review.created_at) %> ago diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb index 7be47ad..efce1de 100644 --- a/app/views/reviews/new.html.erb +++ b/app/views/reviews/new.html.erb @@ -3,9 +3,6 @@ <%= form_with(model: [@movie, @review]) do |f| %> <%= render "shared/errors", object: @review %> - <%= f.label :name %> - <%= f.text_field :name, autofocus: true %> - <%= f.label :stars %> <%= f.select :stars, [1, 2, 3, 4, 5], prompt: "Pick one" %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index c8ac777..8262f52 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -7,4 +7,23 @@ <%= link_to "Delete Account", user_path(@user), class: "button delete", data: { turbo_method: :delete, turbo_confirm: "Permanently delete your account!?" } %> <% end %> + <% if @reviews.present? %> +
+ <%= review.comment %> +
+