Class: RailsBlogEngine::CommentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/rails_blog_engine/comments_controller.rb', line 8

def create
  @comment = @post.comments.create(params[:comment]) do |c|
    # Record some extra information from our environment.  Most of this
    # is used by the spam filter.
    c.author_ip = request.remote_ip
    c.author_user_agent = request.env['HTTP_USER_AGENT']
    c.author_can_post = can?(:create, RailsBlogEngine::Post)
    c.referrer = request.env['HTTP_REFERER']
  end

  if @comment.valid?
    @comment.run_spam_filter
    if @comment.filtered_as_spam?
      flash[:comment_notice] = "Your comment has been held for moderation."
      redirect_to(post_permalink_path(@post) + '#comment-flash')
    else
      redirect_to(post_permalink_path(@post) + "#comment-#{@comment.id}")
    end
  else
    render "new"
  end
end

#mark_as_hamObject



36
37
38
39
# File 'app/controllers/rails_blog_engine/comments_controller.rb', line 36

def mark_as_ham
  @comment.mark_as_ham!
  redirect_to(post_permalink_path(@post) + "#comment-#{@comment.id}")
end

#mark_as_spamObject



31
32
33
34
# File 'app/controllers/rails_blog_engine/comments_controller.rb', line 31

def mark_as_spam
  @comment.mark_as_spam!
  redirect_to(post_permalink_path(@post) + "#comment-#{@comment.id}")
end