comment updates

This commit is contained in:
Mark Moser
2017-02-13 16:12:59 -06:00
parent da5dc4bd94
commit 39ba1a8369
4 changed files with 36 additions and 12 deletions

View File

@ -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

View File

@ -1,5 +1,6 @@
<%= render partial: 'shared/form_model_errors', locals: { obj: @comment } %>
<% # admin_update_comment_path # admin_create_comment_path %>
<%= form_for @comment, url: admin_create_comment_path(test_hash), method: :post do |form| %>
<div class="form-group">
<%= form.label :message, "Comment" %>