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

38 lines
1.1 KiB
Ruby
Raw 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-13 16:12:59 -06:00
authorize QuizComment
2017-02-13 15:54:57 -06:00
comment = QuizComment.create(
comment_params.merge(user_id: current_user.id, test_hash: params[:test_hash])
)
2017-02-13 16:12:59 -06:00
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
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