Module: TheComments::Controller

Extended by:
ActiveSupport::Concern
Included in:
CommentsController
Defined in:
app/controllers/concerns/controller.rb

Overview

Base functionality of Comments Controller class CommentsController < ApplicationController

include TheComments::Controller

end

Instance Method Summary collapse

Instance Method Details

#createObject



112
113
114
115
116
117
118
119
# File 'app/controllers/concerns/controller.rb', line 112

def create
  @comment = @commentable.comments.new comment_params
  if @comment.valid?
    @comment.save
    return render layout: false, partial: comment_partial(:comment), locals: { tree: @comment }
  end
  render json: { errors: @comment.errors.full_messages }
end

#editObject



68
69
70
71
# File 'app/controllers/concerns/controller.rb', line 68

def edit
  @comments = current_user.comcoms.where(id: params[:id]).page(params[:page])
  render comment_template(:manage)
end

#indexObject

App side methods (you can overwrite them)



53
54
55
56
# File 'app/controllers/concerns/controller.rb', line 53

def index
  @comments = ::Comment.with_state(:published).recent.page(params[:page])
  render comment_template(:index)
end

#manageObject



58
59
60
61
# File 'app/controllers/concerns/controller.rb', line 58

def manage
  @comments = current_user.comcoms.active.recent.page(params[:page])
  render comment_template(:manage)
end

#my_commentsObject



63
64
65
66
# File 'app/controllers/concerns/controller.rb', line 63

def my_comments
  @comments = current_user.my_comments.active.recent.page(params[:page])
  render comment_template(:my_comments)
end

#spamObject



94
95
96
97
# File 'app/controllers/concerns/controller.rb', line 94

def spam
  @comments = current_user.comcoms.where(spam: true).recent.page(params[:page])
  render comment_template(:manage)
end

#to_spamObject



129
130
131
132
133
134
# File 'app/controllers/concerns/controller.rb', line 129

def to_spam
  comment = ::Comment.find(params[:id])
  comment.to_spam
  comment.to_deleted
  render nothing: true
end

#total_spamObject



99
100
101
102
# File 'app/controllers/concerns/controller.rb', line 99

def total_spam
  @comments = ::Comment.where(spam: true).recent.page(params[:page])
  render comment_template(:manage)
end

#updateObject

BASE METHODS Public methods



106
107
108
109
110
# File 'app/controllers/concerns/controller.rb', line 106

def update
  comment = ::Comment.find(params[:id])
  comment.update_attributes!(patch_comment_params)
  render(layout: false, partial: comment_partial(:comment_body), locals: { comment: comment })
end