Improve contest view
This commit is contained in:
parent
7ec51b6d85
commit
785e523ebe
@ -1,6 +1,6 @@
|
|||||||
class PuzzlesController < ApplicationController
|
class PuzzlesController < ApplicationController
|
||||||
before_action :set_contest
|
before_action :set_contest
|
||||||
before_action :set_puzzle, only: %i[ show destroy ]
|
before_action :set_puzzle, only: %i[ edit destroy show update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@puzzles = Puzzle.all
|
@puzzles = Puzzle.all
|
||||||
@ -9,6 +9,10 @@ class PuzzlesController < ApplicationController
|
|||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@title = "Edit contest puzzle"
|
||||||
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@puzzle = Puzzle.new
|
@puzzle = Puzzle.new
|
||||||
@title = "New contest puzzle"
|
@title = "New contest puzzle"
|
||||||
@ -25,6 +29,14 @@ class PuzzlesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @puzzle.update(puzzle_params)
|
||||||
|
redirect_to @contest
|
||||||
|
else
|
||||||
|
render :edit, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@puzzle.destroy
|
@puzzle.destroy
|
||||||
redirect_to puzzles_path
|
redirect_to puzzles_path
|
||||||
|
@ -1,31 +1,37 @@
|
|||||||
.row.mb-2
|
.row.mb-2
|
||||||
.col
|
.col
|
||||||
- @badges.each do |badge|
|
css:
|
||||||
span.badge.text-bg-info.me-2
|
.badges { margin-top: -18px; position: absolute; }
|
||||||
= badge
|
.badges
|
||||||
|
- @badges.each do |badge|
|
||||||
.row.mb-4
|
span.badge.text-bg-info.me-2
|
||||||
.col
|
= badge
|
||||||
a.btn.btn-primary href=edit_contest_path(@contest)
|
|
||||||
| Edit contest
|
|
||||||
|
|
||||||
.row.mb-4
|
|
||||||
.col
|
|
||||||
h4 Puzzles
|
|
||||||
.float-end
|
.float-end
|
||||||
a.btn.btn-primary href=new_contest_puzzle_path(@contest)
|
a.btn.btn-primary href=edit_contest_path(@contest)
|
||||||
| Add puzzle
|
| Edit contest
|
||||||
|
|
||||||
|
.row.mb-4
|
||||||
|
.col
|
||||||
|
.row
|
||||||
|
.col
|
||||||
|
h4
|
||||||
|
| Puzzles
|
||||||
.row.row-cols-1.row-cols-md-3.g-4.mb-4
|
.row.row-cols-1.row-cols-md-3.g-4.mb-4
|
||||||
- @puzzles.each do |puzzle|
|
- @puzzles.each do |puzzle|
|
||||||
.col
|
.col
|
||||||
|
css:
|
||||||
|
.card:hover { background-color: lightblue; }
|
||||||
.card.h-100
|
.card.h-100
|
||||||
.card-header
|
.card-header
|
||||||
= puzzle.name
|
= puzzle.name
|
||||||
= image_tag puzzle.image, class: "card-img-top" if puzzle.image.attached?
|
= image_tag puzzle.image if puzzle.image.attached?
|
||||||
.card-body
|
.card-body
|
||||||
p.card-text
|
p.card-text
|
||||||
| TODO puzzle.brand
|
| TODO puzzle.brand
|
||||||
a.btn.btn-primary href=edit_contest_puzzle_path(@contest, puzzle)
|
a.stretched-link href=edit_contest_puzzle_path(@contest, puzzle)
|
||||||
| Edit
|
.row
|
||||||
|
.col
|
||||||
|
a.btn.btn-primary href=new_contest_puzzle_path(@contest)
|
||||||
|
| Add puzzle
|
||||||
.col
|
.col
|
||||||
h4 Teams
|
h4 Teams
|
@ -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
|
.row.mb-3
|
||||||
.col
|
.col
|
||||||
.form-floating
|
.form-floating
|
||||||
|
1
app/views/puzzles/edit.html.slim
Normal file
1
app/views/puzzles/edit.html.slim
Normal file
@ -0,0 +1 @@
|
|||||||
|
= render "form", contest: @contest, puzzle: @puzzle, submit_text: "Save", method: :patch, url: "/contests/#{@contest.id}/puzzles/#{@puzzle.id}"
|
@ -1 +1 @@
|
|||||||
= render "form", contest: @contest, puzzle: @puzzle, submit_text: "Add"
|
= render "form", contest: @contest, puzzle: @puzzle, submit_text: "Add", method: :post, url: "/contests/#{@contest.id}/puzzles"
|
Loading…
x
Reference in New Issue
Block a user