Compare commits
2 Commits
2f23938e81
...
6afde8a971
Author | SHA1 | Date | |
---|---|---|---|
6afde8a971 | |||
70005468c6 |
25
app/controllers/messages_controller.rb
Normal file
25
app/controllers/messages_controller.rb
Normal 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
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user