Skip to content

Commit

Permalink
Reviews Controller create refactor on issue #70
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjmrf committed Mar 28, 2023
1 parent a3bc587 commit 6e96fd7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/controllers/reviews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ class ReviewsController < ApplicationController

def create
@game = Game.find(params[:game_id])
@review = @game.reviews.new(review_params)
@review = @game.reviews.build(review_params)
@review.user = current_user
@review.posted_at = Time.now
@review.posted_at = Time.current

if @review.save
@game.update_attribute(:rate_game, @game.calculate_average_rating)
redirect_to game_path(@game), notice: "Review enviada com sucesso!"
@game.update(rate_game: @game.calculate_average_rating)
redirect_to @game, notice: "Review enviada com sucesso!"
else
redirect_to game_path(@game), alert: "Não foi possível enviar a review."
redirect_to @game, alert: "Não foi possível enviar a review."
end
end

Expand Down

0 comments on commit 6e96fd7

Please sign in to comment.