Class: Studies::CommentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

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

#destroyObject



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

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

#indexObject



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

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