From fea9476a591559bd8fdcf17b64e5114c592a5b08 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Mon, 11 Nov 2024 16:55:14 +0100 Subject: C'est l'heure d'assurer le suivi de quelques flacons! --- app/controllers/application_controller.rb | 4 +++ app/controllers/concerns/.keep | 0 app/controllers/wines_controller.rb | 49 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/controllers/wines_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..0d95db2 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,4 @@ +class ApplicationController < ActionController::Base + # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. + allow_browser versions: :modern +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 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 -- cgit v1.2.3