diff options
author | Marius Peter <marius.peter@tutanota.com> | 2024-11-11 16:55:14 +0100 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2024-11-11 16:55:14 +0100 |
commit | fea9476a591559bd8fdcf17b64e5114c592a5b08 (patch) | |
tree | 08aa0fdd62752f1d286aa66ac77413fb03d6d737 /app/controllers/wines_controller.rb |
C'est l'heure d'assurer le suivi de quelques flacons!main
Diffstat (limited to 'app/controllers/wines_controller.rb')
-rw-r--r-- | app/controllers/wines_controller.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/controllers/wines_controller.rb b/app/controllers/wines_controller.rb new file mode 100644 index 0000000..9129dee --- /dev/null +++ b/app/controllers/wines_controller.rb @@ -0,0 +1,49 @@ +class WinesController < ApplicationController + def index + @wines = Wine.all + end + + def show + @wine = Wine.find(params[:id]) + end + + def new + @wine = Wine.new + end + + def create + @wine = Wine.new(wine_params) + + if @wine.save + redirect_to @wine + else + render :new, status: :unprocessable_entity + end + end + + def edit + @wine = Wine.find(params[:id]) + end + + def update + @wine = Wine.find(params[:id]) + + if @wine.update(wine_params) + redirect_to @wine + else + render :edit, status: :unprocessable_entity + end + end + + def destroy + @wine = Wine.find(params[:id]) + @wine.destroy + + redirect_to root_path, status: :see_other + end + + private + def wine_params + params.require(:wine).permit(:name, :year, :variety, :notes) + end +end |