Class: Commentui::CommentsController

Inherits:
ApplicationController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/commentui/comments_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#check_commentui_user, #commentui_user, #record_not_found, #render_json_errors

Instance Method Details

#createObject



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

def create
  @comment = comments_scope.new(comment_params)
  @comment.creator = commentui_user
  return render json: @comment if @comment.save

  render_json_errors(@comment.errors.full_messages)
end

#destroyObject



34
35
36
# File 'app/controllers/commentui/comments_controller.rb', line 34

def destroy
  render json: @comment.destroy
end

#indexObject



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

def index
  @comments = comments_scope.includes(:creator, :editor)
  @pagy, @comments = pagy(@comments, items: params[:items])
  render json: @comments
end

#updateObject



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

def update
  @comment.assign_attributes(comment_params)
  @comment.editor = commentui_user
  return render json: @comment if @comment.save

  render_json_errors(@comment.errors.full_messages)
end