From 17d660fd4b8516d6b446f7c41d7b076a29a242a1 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 12 Oct 2023 17:44:38 -0400 Subject: Added comment deleting Also I seem to have fixed the JS errors that were preventing the fancy stuff in the admin panel from working. --- app/controllers/admin/comments_controller.rb | 23 +++++++++++++++++++++++ app/helpers/admin/comments_helper.rb | 2 ++ app/views/admin/comments/index.html.haml | 23 +++++++++++++++++++++++ app/views/comments/_comment.html.haml | 2 +- app/views/layouts/admin.html.haml | 2 ++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/comments_controller.rb create mode 100644 app/helpers/admin/comments_helper.rb create mode 100644 app/views/admin/comments/index.html.haml (limited to 'app') diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb new file mode 100644 index 0000000..bd255ad --- /dev/null +++ b/app/controllers/admin/comments_controller.rb @@ -0,0 +1,23 @@ +class Admin::CommentsController < Admin::AdminController + before_action :set_section + + def index + @comments = Comment.order(updated_at: :desc).paginate(page: params[:page], per_page: 20) + end + + def destroy + if Comment.destroy(params[:id]) + flash.notice = "Comment successfully deleted." + else + flash.alert = "Could not delete comment." + end + + redirect_to admin_comments_url + end + + private + + def set_section + @section = "comments" + end +end diff --git a/app/helpers/admin/comments_helper.rb b/app/helpers/admin/comments_helper.rb new file mode 100644 index 0000000..ce9444d --- /dev/null +++ b/app/helpers/admin/comments_helper.rb @@ -0,0 +1,2 @@ +module Admin::CommentsHelper +end diff --git a/app/views/admin/comments/index.html.haml b/app/views/admin/comments/index.html.haml new file mode 100644 index 0000000..7b25c05 --- /dev/null +++ b/app/views/admin/comments/index.html.haml @@ -0,0 +1,23 @@ +- title "Comments" +%table#entries + %tr + %th Text + %th Author + %th Blog post + %th Date published + %th + - @comments.each do |comment| + %tr{ class: cycle("even", "odd") } + %td= comment.body + %td + %ul + %li= comment.username + %li= comment.email + - unless comment.website.empty? + %li= comment.website + %td= link_to comment.blog.title, comment.blog + %td= comment.published_at.strftime("%B %d, %Y, %l:%M%P") + %td + %ul.admin-actions + %li= link_to "View", blog_url(comment.blog, anchor: "comment-#{comment.id}") + %li= link_to "Delete", admin_comment_url(comment), method: :delete, data: { confirm: "Are you sure?" } diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 3e10759..3ad21e9 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -1,4 +1,4 @@ -.blog-comment +.blog-comment{ id: "comment-#{comment.id}" } %blockquote.bubble.rounded.bottom = image_tag comment.gravatar_url, class: "comment-avatar" = markdown(comment.body, { restricted: true }) diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 1c865b0..5d75ef5 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -37,5 +37,7 @@ = link_to "Games", admin_games_url, class: "major-link" %ul.minors %li.minor= link_to "New game", new_admin_game_url + %li{major_sidebar_attrs("comments")} + = link_to "Comments", admin_comments_url, class: "major-link" #main = yield -- cgit 1.4.1