mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
29 lines
587 B
Ruby
29 lines
587 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 if current_user == rating.user
|
|
redirect_to user_path current_user
|
|
end
|
|
end
|