21 行
606 B
Ruby
21 行
606 B
Ruby
class GekanatorQuestionSuggestionsController < ApplicationController
|
|
def create
|
|
return head :not_found unless current_user&.admin?
|
|
|
|
game = GekanatorGame.find_by(id: params.require(:gekanator_game_id))
|
|
return head :not_found unless game
|
|
|
|
suggestion = GekanatorQuestionSuggestion.new(
|
|
gekanator_game: game,
|
|
user: current_user,
|
|
question_text: params.require(:question_text),
|
|
answer: params.require(:answer))
|
|
|
|
if suggestion.save
|
|
render json: { id: suggestion.id }, status: :created
|
|
else
|
|
render_validation_error suggestion
|
|
end
|
|
end
|
|
end
|