Class: Receptacles::CommentsController

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

Overview

Ad and view comments on receptacles

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
# File 'app/controllers/receptacles/comments_controller.rb', line 17

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

#destroyObject



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

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

#indexObject



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

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