skill-assessment-app/app/controllers/admin/comment_controller.rb

38 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2017-02-13 15:54:57 -06:00
# frozen_string_literal: true
module Admin
class CommentController < AdminController
2017-02-13 16:12:59 -06:00
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
2017-02-13 15:54:57 -06:00
def create
2017-02-14 10:17:42 -06:00
comment = QuizComment.new(comment_params.merge(user_id: current_user.id, test_hash: params[:test_hash]))
authorize comment
2017-02-13 15:54:57 -06:00
2017-02-14 10:17:42 -06:00
flash_message = if comment.save
2017-02-13 16:12:59 -06:00
{ success: "Sucessfully created comment" }
else
{ error: "Failed to save comment" }
end
ReviewerMailer.new_comment(comment).deliver_later if comment.persisted?
2017-02-13 16:12:59 -06:00
redirect_to admin_result_path(params[:test_hash]), flash: flash_message
2017-02-13 15:54:57 -06:00
end
private
def comment_params
2017-02-13 16:12:59 -06:00
params.require(:quiz_comment).permit(:message)
2017-02-13 15:54:57 -06:00
end
end
end