Class: CamaleonCms::Admin::CommentsController
- Inherits:
-
CamaleonCms::AdminController
- Object
- CamaleonCms::AdminController
- CamaleonCms::Admin::CommentsController
- Includes:
- CommentHelper
- Defined in:
- app/controllers/camaleon_cms/admin/comments_controller.rb
Overview
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License (GPLv3) for more details.
Instance Method Summary collapse
-
#answer ⇒ Object
render a form to register a new comment.
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
-
#index ⇒ Object
list of post comments for current post.
- #list ⇒ Object
- #new ⇒ Object
-
#save_answer ⇒ Object
save a new anwer for this comment.
-
#toggle_status ⇒ Object
toggle status of a comment.
- #update ⇒ Object
Methods included from CommentHelper
#cama_comments_get_common_data, #cama_comments_render_html
Instance Method Details
#answer ⇒ Object
render a form to register a new comment
29 30 31 32 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 29 def answer @answer = @comment.children.new render 'form_answer', layout: false end |
#create ⇒ Object
64 65 66 67 68 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 64 def create comment = @post.comments.create(cama_comments_get_common_data.merge({post_id: @post.id, content: params[:comment][:content]})) flash[:notice] = t('camaleon_cms.admin.comments.message.responses') redirect_to action: :index end |
#destroy ⇒ Object
70 71 72 73 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 70 def destroy flash[:notice] = t('camaleon_cms.admin.comments.message.destroy') if @comment.destroy redirect_to action: :index end |
#edit ⇒ Object
24 25 26 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 24 def edit render 'form', layout: false end |
#index ⇒ Object
list of post comments for current post
20 21 22 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 20 def index @comments = @post.comments.main.paginate(:page => params[:page], :per_page => current_site.admin_per_page) end |
#list ⇒ Object
15 16 17 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 15 def list @posts = current_site.posts.no_trash.joins(:comments).select("#{CamaleonCms::Post.table_name}.*, #{CamaleonCms::PostComment.table_name}.post_id").uniq.paginate(:page => params[:page], :per_page => current_site.admin_per_page) end |
#new ⇒ Object
59 60 61 62 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 59 def new @comment = @post.comments.new render 'form', layout: false end |
#save_answer ⇒ Object
save a new anwer for this comment
35 36 37 38 39 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 35 def save_answer answer = @comment.children.create(cama_comments_get_common_data.merge({post_id: @post.id, content: params[:comment][:content]})) flash[:notice] = t('camaleon_cms.admin.comments.message.responses') redirect_to action: :index end |
#toggle_status ⇒ Object
toggle status of a comment
42 43 44 45 46 47 48 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 42 def toggle_status _s = {a: "approved", s: "spam", p: "pending"} k = _s[params[:s].to_sym] @comment.update(approved: k) flash[:notice] = "#{t('camaleon_cms.admin.comments.message.change_status')} #{t("camaleon_cms.admin.comments.message.#{k}")}" redirect_to action: :index end |
#update ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 50 def update if @comment.update(content: params[:comment][:content]) flash[:notice] = t('camaleon_cms.admin.comments.message.updated') redirect_to action: :index else render 'form' end end |