From 6f07ec802fc56b65264df1eec75258dc42e13ba2 Mon Sep 17 00:00:00 2001 From: sto Date: Sun, 16 Mar 2025 15:00:54 +0100 Subject: [PATCH] Allow to delete puzzles --- app/controllers/puzzles_controller.rb | 2 +- app/models/contest.rb | 4 ++-- app/models/puzzle.rb | 2 +- app/views/puzzles/_form.html.slim | 4 +++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/puzzles_controller.rb b/app/controllers/puzzles_controller.rb index 2448f50..0b9584a 100644 --- a/app/controllers/puzzles_controller.rb +++ b/app/controllers/puzzles_controller.rb @@ -39,7 +39,7 @@ class PuzzlesController < ApplicationController def destroy @puzzle.destroy - redirect_to puzzles_path + redirect_to contest_path(@contest) end private diff --git a/app/models/contest.rb b/app/models/contest.rb index 060698f..cf9f558 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -1,4 +1,4 @@ class Contest < ApplicationRecord - belongs_to :user, dependent: :destroy - has_many :puzzles + belongs_to :user + has_many :puzzles, dependent: :destroy end diff --git a/app/models/puzzle.rb b/app/models/puzzle.rb index 7630b01..37f8765 100644 --- a/app/models/puzzle.rb +++ b/app/models/puzzle.rb @@ -1,5 +1,5 @@ class Puzzle < ApplicationRecord - belongs_to :contest, dependent: :destroy + belongs_to :contest has_one_attached :image validates :name, presence: true end diff --git a/app/views/puzzles/_form.html.slim b/app/views/puzzles/_form.html.slim index 606d571..0cc8255 100644 --- a/app/views/puzzles/_form.html.slim +++ b/app/views/puzzles/_form.html.slim @@ -8,6 +8,8 @@ .col .form-text Select an image = form.file_field :image, accept: "image/*", class: "form-control" - .row + .row.mt-4 .col + - if method == :patch + = link_to "Delete", contest_puzzle_path(contest, puzzle), data: { turbo_method: :delete }, class: "btn btn-danger me-2" = form.submit submit_text, class: "btn btn-primary" \ No newline at end of file