Class: Labware::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/labware/comments_controller.rb

Overview

Add comments to labware

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Methods included from FlashTruncation

#max_flash_size, #truncate_flash, #truncate_flash_array

Instance Method Details

#createObject



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

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

#destroyObject



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

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

#indexObject



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

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