class Admin::PostCommentsController < Admin::ApplicationController include BlogUrlHelpers respond_to :html, :xml, :json before_action :load_blog, :only => :index before_action :find_comment, :only => [:show, :edit, :update, :destroy, :approve, :spam] def index @page_name = "Comments" if params[:post_id] @post_comments = SpudPostComment.where(:spud_post_id => params[:post_id]) else @post_comments = SpudPostComment.for_blog(params[:blog_key]) end @post_comments = @post_comments.ordered.includes(:post).paginate(:page => params[:page], :per_page => 15) respond_with @post_comments end def show respond_with @post_comment end def edit respond_with @post_comment end def update end def create end def approve if Spud::Blog.enable_rakismet && @post_comment.spam @post_comment.ham! end @post_comment.spam = false @post_comment.approved = true @post_comment.save() redirect_to request.referer || admin_post_post_comments_path(@post_comment.post) end def spam if Spud::Blog.enable_rakismet && !@post_comment.spam @post_comment.spam! end @post_comment.spam = true @post_comment.approved = false @post_comment.save() redirect_to request.referer || admin_post_post_comments_path(@post_comment.post) end def destroy if !@post_comment.destroy flash[:error] = "Whoops! Something odd happened while trying to delete that comment. Thats not fun. please try again." end respond_with @post_comment, :location => request.referer || admin_post_post_comments_path(@post_comment.post) end private def find_comment @post_comment = SpudPostComment.find(params[:id]) end def load_blog @config = SpudBlogConfig.find(params[:blog_key]) if @config.blank? redirect_to admin_root_path return false else self.class.belongs_to_spud_app "#{@config.name} Posts".parameterize.underscore.to_sym add_breadcrumb "#{@config.name} Posts", admin_posts_path(blog_key: @config.key) add_breadcrumb "Comments", admin_post_comments_path(blog_key: @config.key) end end end