Sha256: 317b6f405bf0e1a0ca740482188cb6a770b758d5567caa895e632ae18ab47232

Contents?: true

Size: 1.54 KB

Versions: 79

Compression:

Stored size: 1.54 KB

Contents

module Tenon
  class CommentsController < Tenon::ResourcesController
    before_filter :get_comment, only: [:approve, :unapprove, :destroy]

    def index
      respond_to do |format|
        format.html do
          @counts = {
            all: Tenon::Comment.count,
            approved: Tenon::Comment.approved.count,
            unapproved: Tenon::Comment.unapproved.count
          }
        end
        format.json do
          @comments = Tenon::Comment.all
          @comments = @comments.where(search_args) if params[:q]
          if %w(approved unapproved).include?(params[:type])
            @comments = @comments.send(params[:type])
          end
          @comments = @comments.paginate(per_page: 20, page: params[:page])
          @comments = Tenon::PaginatingDecorator.decorate(@comments)
        end
      end
    end

    def toggle_approved
      respond_to do |format|
        if @comment.toggle_approved!
          format.json { render json: @comment.to_json }
          format.html { flash[:notice] = 'Comment approved.' and redirect_to comments_path }
        else
          format.json { render status: 500, nothing: true }
          format.html { flash[:warning] = 'Error approving comment.' and redirect_to comments_path }
        end
      end
    end

    private

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

    def search_args
      [
        'author ILIKE :q OR author_url ILIKE :q OR author_email ILIKE :q OR content ILIKE :q OR user_ip ILIKE :q',
        { q: "%#{params[:q]}%" }
      ]
    end
  end
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
tenon-1.1.4 app/controllers/tenon/comments_controller.rb
tenon-1.1.3 app/controllers/tenon/comments_controller.rb
tenon-1.1.2 app/controllers/tenon/comments_controller.rb
tenon-1.1.1 app/controllers/tenon/comments_controller.rb
tenon-1.0.76 app/controllers/tenon/comments_controller.rb
tenon-1.0.75 app/controllers/tenon/comments_controller.rb
tenon-1.0.74 app/controllers/tenon/comments_controller.rb
tenon-1.0.73 app/controllers/tenon/comments_controller.rb
tenon-1.0.72 app/controllers/tenon/comments_controller.rb
tenon-1.0.71 app/controllers/tenon/comments_controller.rb
tenon-1.0.70 app/controllers/tenon/comments_controller.rb
tenon-1.0.69 app/controllers/tenon/comments_controller.rb
tenon-1.0.68 app/controllers/tenon/comments_controller.rb
tenon-1.0.67 app/controllers/tenon/comments_controller.rb
tenon-1.0.66 app/controllers/tenon/comments_controller.rb
tenon-1.0.65 app/controllers/tenon/comments_controller.rb
tenon-1.0.64 app/controllers/tenon/comments_controller.rb
tenon-1.0.63 app/controllers/tenon/comments_controller.rb
tenon-1.0.62 app/controllers/tenon/comments_controller.rb
tenon-1.0.61 app/controllers/tenon/comments_controller.rb