Check teams array before calling create method
This commit is contained in:
parent
a14a5224e5
commit
08d2ae59a5
|
|
@ -4,6 +4,7 @@ class TournamentsController < ApplicationController
|
||||||
before_action :set_tournament, only: %i[show update destroy]
|
before_action :set_tournament, only: %i[show update destroy]
|
||||||
before_action :authenticate_user!, only: %i[create update destroy]
|
before_action :authenticate_user!, only: %i[create update destroy]
|
||||||
before_action -> { require_owner! @tournament.owner }, only: %i[update destroy]
|
before_action -> { require_owner! @tournament.owner }, only: %i[update destroy]
|
||||||
|
before_action :validate_create_params, only: %i[create]
|
||||||
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_error
|
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_error
|
||||||
|
|
||||||
# GET /tournaments
|
# GET /tournaments
|
||||||
|
|
@ -71,4 +72,11 @@ class TournamentsController < ApplicationController
|
||||||
def tournament_params
|
def tournament_params
|
||||||
params.slice(:name, :description, :public, :teams).permit!
|
params.slice(:name, :description, :public, :teams).permit!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_create_params
|
||||||
|
teams = params['teams']
|
||||||
|
return if teams.is_a?(Array) && teams.reject { |t| t.is_a? ActionController::Parameters }.count.zero?
|
||||||
|
|
||||||
|
render json: { error: 'Invalid teams array' }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue