diff --git a/app/assets/stylesheets/admin/posts.css.scss b/app/assets/stylesheets/admin/posts.css.scss index 319ea67..918527d 100644 --- a/app/assets/stylesheets/admin/posts.css.scss +++ b/app/assets/stylesheets/admin/posts.css.scss @@ -34,6 +34,10 @@ } } + .pre { + white-space: pre; + } + } .edit-post-link { diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb new file mode 100644 index 0000000..b68c047 --- /dev/null +++ b/app/controllers/admin/comments_controller.rb @@ -0,0 +1,23 @@ +class Admin::CommentsController < ApplicationController + layout 'layouts/admin' + before_action :authericate_user! + + before_action do + @post = Post.find( params[:post_id] ) + end + + def index + @comments = @post.comments + end + + def destroy + comment = @post.comments.find(params[:id]) + if comment.destroy + flash[:notice] = '删除评论成功' + redirect_to admin_post_comments_path(@post) + else + flash[:alert] = '删除失败' + redirect_to admin_post_comments_path(@post) + end + end +end diff --git a/app/views/admin/comments/index.html.slim b/app/views/admin/comments/index.html.slim new file mode 100644 index 0000000..b57f847 --- /dev/null +++ b/app/views/admin/comments/index.html.slim @@ -0,0 +1,23 @@ +.row.admin-posts-field + .small-12.columns + h3.blog-title 评论管理 + h4.blog-title + = link_to @post.title, blog_path(@post), target: '_blank' + table width="100%" + thead + tr + th 名字 + th 邮箱 + th 内容 + th 操作 + tbody + - @comments.each do |comment| + tr + td #{comment.name} + td + = mail_to comment.email + td + p.pre #{comment.content} + td + = link_to '回复', blog_path(@post), target: '_blank', class: 'edit-post-link' + = link_to '删除', admin_post_comment_path(@post, comment), method: 'DELETE', 'data-confirm'=> '确认删除?' diff --git a/app/views/admin/posts/index.html.slim b/app/views/admin/posts/index.html.slim index 0ceb9c8..b0659db 100644 --- a/app/views/admin/posts/index.html.slim +++ b/app/views/admin/posts/index.html.slim @@ -24,6 +24,7 @@ i.fi-heart span #{ post.liked_count } td + = link_to '评论', admin_post_comments_path(post.id), class: 'edit-post-link' = link_to '编辑', edit_admin_post_path(post), class: 'edit-post-link' = link_to '删除', admin_post_path(post), method: 'DELETE', confirm: '确认删除?' diff --git a/config/routes.rb b/config/routes.rb index 57ba389..df55ccf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,6 +30,7 @@ WBlog::Application.routes.draw do collection do post :preview end + resources :comments end resources :sessions, :only=>[:new, :create, :destroy] root to: 'dashboard#index' diff --git a/spec/controllers/admin/comments_controller_spec.rb b/spec/controllers/admin/comments_controller_spec.rb new file mode 100644 index 0000000..589dff6 --- /dev/null +++ b/spec/controllers/admin/comments_controller_spec.rb @@ -0,0 +1,4 @@ +require 'spec_helper' + +describe Admin::CommentsController do +end