about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/comments_controller.rb23
-rw-r--r--app/helpers/admin/comments_helper.rb2
-rw-r--r--app/views/admin/comments/index.html.haml23
-rw-r--r--app/views/comments/_comment.html.haml2
-rw-r--r--app/views/layouts/admin.html.haml2
-rw-r--r--config/initializers/js_routes.rb7
-rw-r--r--config/routes.rb2
-rw-r--r--test/controllers/admin/comments_controller_test.rb8
8 files changed, 68 insertions, 1 deletions
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 @@
1class Admin::CommentsController < Admin::AdminController
2 before_action :set_section
3
4 def index
5 @comments = Comment.order(updated_at: :desc).paginate(page: params[:page], per_page: 20)
6 end
7
8 def destroy
9 if Comment.destroy(params[:id])
10 flash.notice = "Comment successfully deleted."
11 else
12 flash.alert = "Could not delete comment."
13 end
14
15 redirect_to admin_comments_url
16 end
17
18 private
19
20 def set_section
21 @section = "comments"
22 end
23end
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 @@
1module Admin::CommentsHelper
2end
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 @@
1- title "Comments"
2%table#entries
3 %tr
4 %th Text
5 %th Author
6 %th Blog post
7 %th Date published
8 %th
9 - @comments.each do |comment|
10 %tr{ class: cycle("even", "odd") }
11 %td= comment.body
12 %td
13 %ul
14 %li= comment.username
15 %li= comment.email
16 - unless comment.website.empty?
17 %li= comment.website
18 %td= link_to comment.blog.title, comment.blog
19 %td= comment.published_at.strftime("%B %d, %Y, %l:%M%P")
20 %td
21 %ul.admin-actions
22 %li= link_to "View", blog_url(comment.blog, anchor: "comment-#{comment.id}")
23 %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 @@
1.blog-comment 1.blog-comment{ id: "comment-#{comment.id}" }
2 %blockquote.bubble.rounded.bottom 2 %blockquote.bubble.rounded.bottom
3 = image_tag comment.gravatar_url, class: "comment-avatar" 3 = image_tag comment.gravatar_url, class: "comment-avatar"
4 = markdown(comment.body, { restricted: true }) 4 = 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 @@
37 = link_to "Games", admin_games_url, class: "major-link" 37 = link_to "Games", admin_games_url, class: "major-link"
38 %ul.minors 38 %ul.minors
39 %li.minor= link_to "New game", new_admin_game_url 39 %li.minor= link_to "New game", new_admin_game_url
40 %li{major_sidebar_attrs("comments")}
41 = link_to "Comments", admin_comments_url, class: "major-link"
40 #main 42 #main
41 = yield 43 = yield
diff --git a/config/initializers/js_routes.rb b/config/initializers/js_routes.rb new file mode 100644 index 0000000..7bc0c65 --- /dev/null +++ b/config/initializers/js_routes.rb
@@ -0,0 +1,7 @@
1JsRoutes.setup do |c|
2 # Setup your JS module system:
3 # ESM, CJS, AMD, UMD or nil
4 # c.module_type = "ESM"
5 c.module_type = nil
6 c.namespace = 'Routes'
7end
diff --git a/config/routes.rb b/config/routes.rb index 2bae007..dcfe673 100644 --- a/config/routes.rb +++ b/config/routes.rb
@@ -15,6 +15,8 @@ Rails.application.routes.draw do
15 resources :links, except: [:show] 15 resources :links, except: [:show]
16 16
17 resources :games, except: [:show] 17 resources :games, except: [:show]
18
19 resources :comments, only: [:index, :destroy]
18 end 20 end
19 21
20 devise_for :users, controllers: { 22 devise_for :users, controllers: {
diff --git a/test/controllers/admin/comments_controller_test.rb b/test/controllers/admin/comments_controller_test.rb new file mode 100644 index 0000000..33f1a47 --- /dev/null +++ b/test/controllers/admin/comments_controller_test.rb
@@ -0,0 +1,8 @@
1require "test_helper"
2
3class Admin::CommentsControllerTest < ActionDispatch::IntegrationTest
4 test "should get index" do
5 get admin_comments_index_url
6 assert_response :success
7 end
8end