From dc3e755dfb891297c2d0377f5b3b0c1ca3a192a0 Mon Sep 17 00:00:00 2001 From: yafeilee Date: Sun, 25 May 2014 10:33:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=84=E8=AE=BA=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/stylesheets/admin/posts.css.scss | 4 ++++ app/controllers/admin/comments_controller.rb | 23 +++++++++++++++++++ app/views/admin/comments/index.html.slim | 23 +++++++++++++++++++ app/views/admin/posts/index.html.slim | 1 + config/routes.rb | 1 + .../admin/comments_controller_spec.rb | 4 ++++ 6 files changed, 56 insertions(+) create mode 100644 app/controllers/admin/comments_controller.rb create mode 100644 app/views/admin/comments/index.html.slim create mode 100644 spec/controllers/admin/comments_controller_spec.rb 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