Files
brewery/app/controllers/ratings_controller.rb
T

29 lines
546 B
Ruby

class RatingsController < ApplicationController
def index
@ratings = Rating.all
end
def new
@rating = Rating.new
@beers = Beer.all
end
def create
@rating = Rating.create params.require(:rating).permit(:score, :beer_id)
@rating.user = current_user
if @rating.save
redirect_to user_path current_user
else
@beers = Beer.all
render :new, status: :unprocessable_entity
end
end
def destroy
rating = Rating.find params[:id]
rating.delete
redirect_to ratings_path
end
end