comment updates
This commit is contained in:
@ -1,26 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
module Admin
|
||||
class CommentController < AdminController
|
||||
before_action { authorize QuizComment }
|
||||
def update
|
||||
comment = QuizComment.find_by(id: params[:id], test_hash: params[:test_hash])
|
||||
authorize comment
|
||||
|
||||
comment.update(comment_params)
|
||||
flash_message = if comment.save
|
||||
{ success: "Sucessfully updated comment" }
|
||||
else
|
||||
{ error: "Failed to update comment" }
|
||||
end
|
||||
redirect_to admin_result_path(params[:test_hash]), flash: flash_message
|
||||
end
|
||||
|
||||
def create
|
||||
authorize QuizComment
|
||||
comment = QuizComment.create(
|
||||
comment_params.merge(user_id: current_user.id, test_hash: params[:test_hash])
|
||||
)
|
||||
|
||||
if comment.persisted?
|
||||
redirect_to admin_result_path(params[:test_hash]),
|
||||
flash: { success: "Sucessfully created comment" }
|
||||
else
|
||||
redirect_to admin_result_path(params[:test_hash]),
|
||||
flash: { error: "Failed to save comment" }
|
||||
end
|
||||
flash_message = if comment.persisted?
|
||||
{ success: "Sucessfully created comment" }
|
||||
else
|
||||
{ error: "Failed to save comment" }
|
||||
end
|
||||
redirect_to admin_result_path(params[:test_hash]), flash: flash_message
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def comment_params
|
||||
params.require(:quiz_comment).permit(:message, :id)
|
||||
params.require(:quiz_comment).permit(:message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user