Class: Comment::CommentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /comments



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

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

#destroyObject

DELETE /comments/1



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

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

  @comment.destroy
end

#indexObject

GET /comments



6
7
8
# File 'app/controllers/comment/comments_controller.rb', line 6

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

#replyObject



22
23
24
25
# File 'app/controllers/comment/comments_controller.rb', line 22

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

#updateObject

PATCH/PUT /comments/1



18
19
20
# File 'app/controllers/comment/comments_controller.rb', line 18

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