upto 2.11

This commit is contained in:
Aaro Koivukangas
2023-08-08 10:32:52 +03:00
parent 852c9b35c3
commit 403a3c3674
3 changed files with 10 additions and 4 deletions
+7
View File
@@ -7,8 +7,15 @@ class RatingsController < ApplicationController
@rating = Rating.new @rating = Rating.new
@beers = Beer.all @beers = Beer.all
end end
def create def create
Rating.create params.require(:rating).permit(:score, :beer_id) Rating.create params.require(:rating).permit(:score, :beer_id)
redirect_to ratings_path redirect_to ratings_path
end end
def destroy
rating = Rating.find params[:id]
rating.delete
redirect_to ratings_path
end
end end
+2 -1
View File
@@ -4,11 +4,12 @@
<% @ratings.each do |rating| %> <% @ratings.each do |rating| %>
<li> <li>
<%= render rating %> <%= render rating %>
<%= button_to "delete", rating_path(rating.id), method: :delete, form: { data: { turbo_confirm: "Are you sure?" }} %>
</li> </li>
<% end %> <% end %>
</ul> </ul>
<p> <p>
<%= link_to "New rating", ratings_new_path %> <%= link_to "New rating", new_rating_path %>
</p> </p>
+1 -3
View File
@@ -6,7 +6,5 @@ Rails.application.routes.draw do
# Defines the root path route ("/") # Defines the root path route ("/")
# root "articles#index" # root "articles#index"
get '/', to: 'breweries#index' get '/', to: 'breweries#index'
get 'ratings', to: 'ratings#index' resources :ratings, only: [:index, :new, :create, :destroy]
post 'ratings', to: 'ratings#create'
get 'ratings/new', to: 'ratings#new'
end end