Class: Requests::CommentsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/requests/comments_controller.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Instance Method Details

#createObject


15
16
17
18
19
# File 'app/controllers/requests/comments_controller.rb', line 15

def create
  @request.comments.create(description: params[:comment], user_id: current_user.id)
  @comments = @request.comments
  render partial: 'list', locals: { commentable: @request, visible: true }
end

#destroyObject


21
22
23
24
25
26
# File 'app/controllers/requests/comments_controller.rb', line 21

def destroy
  comment = Comment.find(params[:id])
  comment.destroy if comment.present?
  @comments = @request.comments
  render partial: 'list', locals: { commentable: @request, visible: true }
end

#indexObject


5
6
7
8
9
10
11
12
13
# File 'app/controllers/requests/comments_controller.rb', line 5

def index
  commentables = [@request, @request.asset, @request.asset&.labware].compact
  @comments = Comment.where(commentable: commentables).order('created_at ASC')
  if request.xhr?
    render partial: 'simple_list', locals: { descriptions: @comments.pluck(:description) }
  else
    # Perform default
  end
end