Class: Forge::CommentsController

Inherits:
ForgeController show all
Defined in:
lib/forge/app/controllers/forge/comments_controller.rb

Instance Method Summary collapse

Methods inherited from ForgeController

#get_menu_items, #load_help, #set_crumbs, #set_title, #uses_ckeditor

Methods inherited from ApplicationController

#app_init

Instance Method Details

#approveObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/forge/app/controllers/forge/comments_controller.rb', line 17

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

#destroyObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/forge/app/controllers/forge/comments_controller.rb', line 41

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

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/forge/app/controllers/forge/comments_controller.rb', line 4

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

#unapproveObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/forge/app/controllers/forge/comments_controller.rb', line 29

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