Class: Notee::CommentsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/notee/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @comment = Comment.new(comment_params)
  if @comment.save
    render json: { status: 'success' }
  else
    render json: { status: 'failed' }
  end
end

#destroyObject



36
37
38
39
40
41
42
43
44
# File 'app/controllers/notee/comments_controller.rb', line 36

def destroy
  respond_to do |format|
    if @comment.update(is_deleted: true)
      format.json { render json: @comment, status: 200 }
    else
      format.json { render json: @comment.errors, status: :internal_server_error }
    end
  end
end

#indexObject



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

def index
  comments = Comment.where(is_deleted: false).order(updated_at: :desc)
  render json: { status: 'success', comments: comments }
end

#showObject



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

def show
  @comments = Comment.where(post_id: params[:id])
  render json: { status: 'success', comments: @comments }
end

#updateObject



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

def update
  respond_to do |format|
    if @comment.update(is_hidden: !@comment.is_hidden)
      format.json { render json: @comment, status: 200 }
    else
      format.json { render json: @comment.errors, status: :unprocessable_entity }
    end
  end
end