Class: Samples::CommentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
# File 'app/controllers/samples/comments_controller.rb', line 12

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

#destroyObject



18
19
20
21
22
23
# File 'app/controllers/samples/comments_controller.rb', line 18

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

#indexObject



8
9
10
# File 'app/controllers/samples/comments_controller.rb', line 8

def index
  @comments = @sample.comments.order(:created_at)
end