Class: CommentsController

Inherits:
BumbleController show all
Defined in:
app/controllers/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#approveObject



88
89
90
91
92
# File 'app/controllers/comments_controller.rb', line 88

def approve
  @comment = Comment.find(params[:id])
  @comment.mark_as_ham!
  redirect_to post_path(@comment.post, :anchor => dom_id(@comment))
end

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/comments_controller.rb', line 5

def create
  @post = Post.find(params[:post_id])
  @comment = Comment.new(params[:comment])
  @comment.user = current_user
  @comment.request = request
  @comment.post = @post

  if @comment.save
    respond_to do |format|
      format.html do
        if @comment.approved?
          flash[:notice] = 'Create successful!'
        else
          flash[:notice] = "Your comment looks like spam, it will show up once it's been approved."
        end
        redirect_to post_path(@post, :anchor => dom_id(@comment))
      end
      format.js do
        if @comment.approved?
          render @comment, :content_type => :html
        else
          render :text => "Your comment looks like spam, it will show up once it's been approved.", :status => 406, :content_type => :html
        end
      end
    end
  else
    respond_to do |format|
      format.html { render :action => "new" }
      format.js   { render :text => @comment.errors.full_messages.join(', ').capitalize, :status => 403, :content_type => :html }
    end
  end
end

#destroyObject



48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/comments_controller.rb', line 48

def destroy
  @comment = Comment.find(params[:id])
  @comment.destroy
  respond_to do |format|
    format.html do
      flash[:notice] = 'Record deleted!'
      redirect_to post_path(@comment.post)
    end
    format.js { render :nothing => true }
  end
end

#editObject



75
76
77
# File 'app/controllers/comments_controller.rb', line 75

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

#indexObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/comments_controller.rb', line 38

def index
  @post = Post.find(params[:post_id])
  @comments = @post.comments
  respond_to do |format|
    format.html { redirect_to post_path(@post, :anchor => 'comments') }
    format.atom {}
    format.js { render @comments }
  end
end

#newObject



79
80
81
# File 'app/controllers/comments_controller.rb', line 79

def new
  @comment = Comment.new
end

#rejectObject



94
95
96
97
98
# File 'app/controllers/comments_controller.rb', line 94

def reject
  @comment = Comment.find(params[:id])
  @comment.mark_as_spam!
  redirect_to post_path(@comment.post, :anchor => dom_id(@comment))
end

#showObject



83
84
85
86
# File 'app/controllers/comments_controller.rb', line 83

def show
  @comment = Comment.find(params[:id])
  redirect_to post_path(@comment.post, :anchor => dom_id(@comment))
end

#updateObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/comments_controller.rb', line 60

def update
  @post = Post.find(params[:post_id])
  @comment = Comment.find(params[:id])
  if @comment.update_attributes(params[:comment])
    respond_to do |format|
      format.html do
        flash[:notice] = 'Save successful!'
        redirect_to post_path(@post, :anchor => dom_id(@comment))
      end
    end
  else
    render :action => 'edit'
  end
end