Class: Requests::CommentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject


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

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


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

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

#indexObject


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

def index
  @comments = @request.comments.order('created_at ASC')
  if request.xhr?
    render partial: 'simple_list', locals: { descriptions: @comments.pluck(:description) }
  else
    # Perform default
  end
end