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
- #create ⇒ Object
- #edit ⇒ Object
-
#index ⇒ Object
App side methods (you can overwrite them).
- #manage ⇒ Object
- #my_comments ⇒ Object
- #spam ⇒ Object
- #to_spam ⇒ Object
- #total_spam ⇒ Object
-
#update ⇒ Object
BASE METHODS Public methods.
Instance Method Details
#create ⇒ Object
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. } end |
#edit ⇒ Object
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 |
#index ⇒ Object
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 |
#manage ⇒ Object
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_comments ⇒ Object
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 |
#spam ⇒ Object
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_spam ⇒ Object
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_spam ⇒ Object
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 |
#update ⇒ Object
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 |