Sha256: 2432de9c5c1eca78490e42c64f38347b50de246e36c9963c1f134f870dabfbb8

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

module Enki
  module Admin
    class CommentsController < BaseController
      before_filter :find_comment, :only => [:show, :update, :destroy]

      def index
        @comments = Comment.order("comments.created_at DESC").includes(:post).paginated(params)
      end

      def show
        respond_to do |format|
          format.html {
            render :partial => 'comment', :locals => {:comment => @comment} if request.xhr?
          }
        end
      end

      def update
        if @comment.update_attributes(params[:comment])
          flash[:notice] = "Updated comment by #{@comment.author}"
          redirect_to [:admin, :comments]
        else
          render :action => 'show'
        end
      end

      def destroy
        undo_item = @comment.destroy_with_undo

        respond_to do |format|
          format.html do
            flash[:notice] = "Deleted comment by #{@comment.author}"
            redirect_to admin_comments_url
          end
          format.json {
            render :json => {
              :undo_path    => undo_admin_undo_item_path(undo_item),
              :undo_message => undo_item.description,
              :comment      => @comment.attributes
            }.to_json
          }
        end
      end

      protected

      def find_comment
        @comment = Comment.find(params[:id])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
enki-engine-0.0.5 app/controllers/enki/admin/comments_controller.rb
enki-engine-0.0.4 app/controllers/enki/admin/comments_controller.rb
enki-engine-0.0.3 app/controllers/enki/admin/comments_controller.rb
enki-engine-0.0.2 app/controllers/enki/admin/comments_controller.rb