Implement message delete method
Some checks failed
CI / scan_ruby (push) Failing after 13s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 41s

This commit is contained in:
sto 2025-05-14 16:37:28 +02:00
parent 138fe67baa
commit 1397ddce2f
3 changed files with 24 additions and 4 deletions

View File

@ -1,8 +1,11 @@
class MessagesController < ApplicationController
allow_unauthenticated_access
skip_before_action :verify_authenticity_token
skip_before_action :verify_authenticity_token, only: %i[ create ]
before_action :set_contest, only: %i[ destroy ]
before_action :set_message, only: %i[ destroy ]
def create
allow_unauthenticated_access
skip_authorization
@message_params = message_params
@ -19,6 +22,23 @@ class MessagesController < ApplicationController
end
end
def destroy
authorize @contest
@message.destroy
redirect_to contest_path(@contest)
end
private
def set_contest
@contest = Contest.find(params[:contest_id])
end
def set_message
@message = Message.find(params[:id])
end
def message_params
params.expect(message: [ :text, :time_seconds, :token ])
end

View File

@ -64,8 +64,7 @@
a.btn.btn-sm.btn-secondary href="" style="white-space: nowrap;"
| Add completion
td
a.btn.btn-sm.btn-danger href=""
| Delete
= link_to "Delete", contest_message_path(@contest, message), data: { turbo_method: :delete }, class: "btn btn-sm btn-danger"
.col-6
.row
.col

View File

@ -12,6 +12,7 @@ Rails.application.routes.draw do
resources :completions
resources :contestants
resources :puzzles
resources :messages
end
resources :passwords, param: :token
resource :session