Class: CommentsProxy::TubeRack

Inherits:
Base
  • Object
show all
Defined in:
app/models/comments_proxy/tube_rack.rb

Overview

When displaying tube rack comments, we also want to show any comments associated with the contained tubes, or their requests.

Instance Method Summary collapse

Methods inherited from Base

#add_comment_to_submissions, #comment_assn, #count, #initialize, #size

Constructor Details

This class inherits a constructor from CommentsProxy::Base

Instance Method Details

#add_comment_to_tubes(comment) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/comments_proxy/tube_rack.rb', line 6

def add_comment_to_tubes(comment)
  comment_records =
    @commentable.tubes.ids.map do |tube_id|
      {
        commentable_type: 'Labware',
        commentable_id: tube_id,
        **comment.attributes.except('id', 'commentable_type', 'commentable_id')
      }
    end

  # NOTE: We use import here to bypass the after_create
  # callbacks on Comment, as the rack has already handled that.
  # If we let the tubes handle it, we'd have lots of duplicate
  # comments.
  Comment.import(comment_records)
end