Sha256: a098e16cbce0b0bc1733bdc482a5b1b301fe36cd59855f06962de4b2b62f56cd

Contents?: true

Size: 1.94 KB

Versions: 6

Compression:

Stored size: 1.94 KB

Contents

class Forge::CommentsController < ForgeController
  before_filter :get_comment, :only => [:approve, :unapprove, :destroy]

  def index
    conditions = ["approved = ?", false] if params[:show] == "unapproved"
    conditions = ["approved = ?", true] if params[:show] == "approved"
    respond_to do |format|
      format.html { @comments = Comment.where(conditions).paginate(:include => :commentable, :per_page => 10, :page => params[:page]) }
      format.js {
        params[:q] ||= ''
        @comments = Comment.where("LOWER(author) LIKE ? OR LOWER(content) LIKE ?", "%#{params[:q].downcase}%", "%#{params[:q].downcase}%")
        render :partial => "comment", :collection => @comments
      }
    end
  end

  def approve
    respond_to do |format|
      if @comment.approve!
        format.js { render :nothing => true }
        format.html { flash[:notice] = "Comment approved." and redirect_to forge_comments_path }
      else
        format.js { render :status => 500 }
        format.html { flash[:warning] = "Error approving comment." and redirect_to forge_comments_path }
      end
    end
  end

  def unapprove
    respond_to do |format|
      if @comment.unapprove!
        format.js { render :nothing => true }
        format.html { flash[:notice] = "Comment unapproved." and redirect_to forge_comments_path }
      else
        format.js { render :status => 500 }
        format.html { flash[:warning] = "Error unapproving comment." and redirect_to forge_comments_path }
      end
    end
  end

  def destroy
    respond_to do |format|
      if @comment.destroy
        format.js { render :nothing => true }
        format.html { flash[:notice] = "Comment deleted." and redirect_to forge_comments_path }
      else
        format.js { render :status => 500 }
        format.html { flash[:warning] = "Error deleting comment." and redirect_to forge_comments_path }
      end
    end
  end

protected

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

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
forge-cli-0.1.10 lib/forge/app/controllers/forge/comments_controller.rb
forge-cli-0.1.9 lib/forge/app/controllers/forge/comments_controller.rb
forge-cli-0.1.8 lib/forge/app/controllers/forge/comments_controller.rb
forge-cli-0.1.7 lib/forge/app/controllers/forge/comments_controller.rb
forge-cli-0.1.6 lib/forge/app/controllers/forge/comments_controller.rb
forge-cli-0.1.5 lib/forge/app/controllers/forge/comments_controller.rb