Class: Studies::CommentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject


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

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


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

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

#indexObject


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

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