comment creation
This commit is contained in:
26
app/controllers/admin/comment_controller.rb
Normal file
26
app/controllers/admin/comment_controller.rb
Normal file
@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
module Admin
|
||||
class CommentController < AdminController
|
||||
before_action { authorize QuizComment }
|
||||
|
||||
def create
|
||||
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
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def comment_params
|
||||
params.require(:quiz_comment).permit(:message, :id)
|
||||
end
|
||||
end
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
<%= render partial: 'shared/form_model_errors', locals: { obj: @comment } %>
|
||||
|
||||
<%= form_for @comment, url: "#", method: :post do |form| %>
|
||||
<%= form_for @comment, url: admin_create_comment_path(test_hash), method: :post do |form| %>
|
||||
<div class="form-group">
|
||||
<%= form.label :message, "Comment" %>
|
||||
<%= form.text_area :message %>
|
||||
|
@ -45,7 +45,7 @@
|
||||
|
||||
<div class="review-comments">
|
||||
<h2 class="prft-heading">Comments</h2>
|
||||
<%= render partial: 'comment', collection: @comments %>
|
||||
<div><%= render partial: 'comment_form' %></div>
|
||||
<%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %>
|
||||
<div><%= render partial: 'comment_form', locals: { test_hash: @candidate.test_hash } %></div>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user