diff --git a/app/controllers/puzzles_controller.rb b/app/controllers/puzzles_controller.rb index 71462d1..2448f50 100644 --- a/app/controllers/puzzles_controller.rb +++ b/app/controllers/puzzles_controller.rb @@ -1,6 +1,6 @@ class PuzzlesController < ApplicationController before_action :set_contest - before_action :set_puzzle, only: %i[ show destroy ] + before_action :set_puzzle, only: %i[ edit destroy show update] def index @puzzles = Puzzle.all @@ -9,6 +9,10 @@ class PuzzlesController < ApplicationController def show end + def edit + @title = "Edit contest puzzle" + end + def new @puzzle = Puzzle.new @title = "New contest puzzle" @@ -25,6 +29,14 @@ class PuzzlesController < ApplicationController end end + def update + if @puzzle.update(puzzle_params) + redirect_to @contest + else + render :edit, status: :unprocessable_entity + end + end + def destroy @puzzle.destroy redirect_to puzzles_path diff --git a/app/views/contests/show.html.slim b/app/views/contests/show.html.slim index ef5f285..533f812 100644 --- a/app/views/contests/show.html.slim +++ b/app/views/contests/show.html.slim @@ -1,31 +1,37 @@ .row.mb-2 .col - - @badges.each do |badge| - span.badge.text-bg-info.me-2 - = badge - -.row.mb-4 - .col - a.btn.btn-primary href=edit_contest_path(@contest) - | Edit contest - -.row.mb-4 - .col - h4 Puzzles + css: + .badges { margin-top: -18px; position: absolute; } + .badges + - @badges.each do |badge| + span.badge.text-bg-info.me-2 + = badge .float-end - a.btn.btn-primary href=new_contest_puzzle_path(@contest) - | Add puzzle + a.btn.btn-primary href=edit_contest_path(@contest) + | Edit contest + +.row.mb-4 + .col + .row + .col + h4 + | Puzzles .row.row-cols-1.row-cols-md-3.g-4.mb-4 - @puzzles.each do |puzzle| .col + css: + .card:hover { background-color: lightblue; } .card.h-100 .card-header = puzzle.name - = image_tag puzzle.image, class: "card-img-top" if puzzle.image.attached? + = image_tag puzzle.image if puzzle.image.attached? .card-body p.card-text | TODO puzzle.brand - a.btn.btn-primary href=edit_contest_puzzle_path(@contest, puzzle) - | Edit + a.stretched-link href=edit_contest_puzzle_path(@contest, puzzle) + .row + .col + a.btn.btn-primary href=new_contest_puzzle_path(@contest) + | Add puzzle .col h4 Teams \ No newline at end of file diff --git a/app/views/puzzles/_form.html.slim b/app/views/puzzles/_form.html.slim index 3f783d1..606d571 100644 --- a/app/views/puzzles/_form.html.slim +++ b/app/views/puzzles/_form.html.slim @@ -1,4 +1,4 @@ -= form_with model: puzzle, url: "/contests/#{contest.id}/puzzles", method: :post do |form| += form_with model: puzzle, url: url, method: method do |form| .row.mb-3 .col .form-floating diff --git a/app/views/puzzles/edit.html.slim b/app/views/puzzles/edit.html.slim new file mode 100644 index 0000000..2bd1726 --- /dev/null +++ b/app/views/puzzles/edit.html.slim @@ -0,0 +1 @@ += render "form", contest: @contest, puzzle: @puzzle, submit_text: "Save", method: :patch, url: "/contests/#{@contest.id}/puzzles/#{@puzzle.id}" \ No newline at end of file diff --git a/app/views/puzzles/new.html.slim b/app/views/puzzles/new.html.slim index fe1c544..16c2f0d 100644 --- a/app/views/puzzles/new.html.slim +++ b/app/views/puzzles/new.html.slim @@ -1 +1 @@ -= render "form", contest: @contest, puzzle: @puzzle, submit_text: "Add" \ No newline at end of file += render "form", contest: @contest, puzzle: @puzzle, submit_text: "Add", method: :post, url: "/contests/#{@contest.id}/puzzles" \ No newline at end of file