Compare commits

...

2 Commits

Author SHA1 Message Date
sto
6afde8a971 Turn puzzles into table
Some checks failed
CI / scan_ruby (push) Failing after 13s
CI / scan_js (push) Successful in 11s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 28s
2025-05-11 21:09:57 +02:00
sto
70005468c6 Add route and controller for incoming messages 2025-05-11 21:09:45 +02:00
4 changed files with 50 additions and 12 deletions

View File

@ -0,0 +1,25 @@
class MessagesController < ApplicationController
allow_unauthenticated_access
skip_before_action :verify_authenticity_token
def create
skip_authorization
@message_params = message_params
@contest = Contest.find_by_token_for(:token, params[:token])
@message = Message.new(text: params[:text], time_seconds: params[:time_seconds], contest: @contest)
if @contest && @message.save
respond_to do |format|
format.json { render json: {}, status: 200 }
end
else
respond_to do |format|
format.json { render json: { error: "invalid contest token" }, status: 400 }
end
end
end
def message_params
params.expect(message: [ :text, :time_seconds, :token ])
end
end

View File

@ -27,8 +27,11 @@ class Contest < ApplicationRecord
has_many :completions, dependent: :destroy
has_many :contestants, dependent: :destroy
has_many :puzzles, dependent: :destroy
has_many :messages
friendly_id :name, use: :slugged
validates :name, presence: true
generates_token_for :token
end

View File

@ -21,19 +21,27 @@
.row
.col
h4 = t("puzzles.plural").capitalize
.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
table.table.table-striped.table-hover
thead
tr
th scope="col"
| Image
th scope="col"
| Title
th scope="col"
| Brand
tbody
- @puzzles.each do |puzzle|
tr.align-middle scope="row"
td
= image_tag(puzzle.image, class: "img-fluid", style: "max-width: 140px;") if puzzle.image.attached?
td
= puzzle.name
= image_tag puzzle.image if puzzle.image.attached?
.card-body
p.card-text
= puzzle.brand
a.stretched-link href=edit_contest_puzzle_path(@contest, puzzle)
td
= puzzle.brand
td
a.btn.btn-sm.btn-secondary href=edit_contest_puzzle_path(@contest, puzzle)
| Edit
.row
.col
a.btn.btn-primary href=new_contest_puzzle_path(@contest)

View File

@ -17,5 +17,7 @@ Rails.application.routes.draw do
resource :session
resources :users
post "message", to: "messages#create"
get "public/:id", to: "contests#scoreboard"
end