Module: TheComments::Controller

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

Overview

Base functionality of Comments Controller class CommentsController < ApplicationController

include TheComments::Controller

end

Instance Method Summary collapse

Instance Method Details

#createObject

Public methods



81
82
83
84
85
86
87
88
# File 'app/controllers/concerns/the_comments/controller.rb', line 81

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 }
end

#editObject

Restricted area



92
93
94
95
# File 'app/controllers/concerns/the_comments/controller.rb', line 92

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

#manageObject

App side methods (you can overwrite them)



33
34
35
36
# File 'app/controllers/concerns/the_comments/controller.rb', line 33

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

#my_commentsObject



38
39
40
41
# File 'app/controllers/concerns/the_comments/controller.rb', line 38

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

#my_spamObject



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

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

#spamObject



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

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

#to_spamObject



110
111
112
113
114
115
# File 'app/controllers/concerns/the_comments/controller.rb', line 110

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

#total_spamObject



72
73
74
75
# File 'app/controllers/concerns/the_comments/controller.rb', line 72

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

#updateObject



97
98
99
100
101
# File 'app/controllers/concerns/the_comments/controller.rb', line 97

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