Class: Comments::CommentsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user!, #current_user

Instance Method Details

#createObject

POST /comments



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

def create
  @comment = Comment.new(comment_params)
  @comment.user = current_user
  @comment.save
end

#destroyObject

DELETE /comments/1



29
30
31
32
33
34
35
# File 'app/controllers/comments/comments_controller.rb', line 29

def destroy
  if @comment.user_id != current_user.id
    raise ActiveRecord::RecordNotFound
  end

  @comment.destroy
end

#indexObject

GET /comments



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

def index
  @comments = Comment.order('id asc').page(params[:page])
end

#replyObject



23
24
25
26
# File 'app/controllers/comments/comments_controller.rb', line 23

def reply
  @parent = Comment.find(params[:id])
  @comment = Comment.new(parent_id: @parent.id, commentable: @parent.commentable)
end

#updateObject

PATCH/PUT /comments/1



19
20
21
# File 'app/controllers/comments/comments_controller.rb', line 19

def update
  @success = @comment.update(comment_params)
end