added errors to creating new rating

This commit is contained in:
Aaro Koivukangas
2023-08-10 17:01:25 +03:00
parent 14c92694a3
commit b0ab392fc2
3 changed files with 21 additions and 3 deletions
+8 -3
View File
@@ -9,10 +9,15 @@ class RatingsController < ApplicationController
end
def create
rating = Rating.create params.require(:rating).permit(:score, :beer_id)
session[:last_rating] = "#{rating.beer.name} #{rating.score} points"
@rating = Rating.create params.require(:rating).permit(:score, :beer_id)
@rating.user = current_user
redirect_to ratings_path
if @rating.save
redirect_to user_path current_user
else
@beers = Beer.all
render :new, status: :unprocessable_entity
end
end
def destroy