添加评论管理功能

This commit is contained in:
yafeilee 2014-05-25 10:33:28 +08:00
parent b18525bfde
commit dc3e755dfb
6 changed files with 56 additions and 0 deletions

View File

@ -34,6 +34,10 @@
}
}
.pre {
white-space: pre;
}
}
.edit-post-link {

View File

@ -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

View File

@ -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'=> '确认删除?'

View File

@ -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: '确认删除?'

View File

@ -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'

View File

@ -0,0 +1,4 @@
require 'spec_helper'
describe Admin::CommentsController do
end