diff --git a/app/controllers/ratings_controller.rb b/app/controllers/ratings_controller.rb index 2c2931c..c968a95 100644 --- a/app/controllers/ratings_controller.rb +++ b/app/controllers/ratings_controller.rb @@ -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 diff --git a/app/views/ratings/new.html.erb b/app/views/ratings/new.html.erb index ae52d6b..616ab6f 100644 --- a/app/views/ratings/new.html.erb +++ b/app/views/ratings/new.html.erb @@ -1,6 +1,18 @@