Class: CommentsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#app_init

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/forge/app/controllers/comments_controller.rb', line 5

def create
  params[:comment].merge!({:user_ip => request.remote_ip, :user_agent => request.env['HTTP_USER_AGENT'], :referrer => request.env['HTTP_REFERER']})
  @comment = Comment.new(params[:comment])
  if @comment.save
    flash[:notice] = "Your comment was submitted successfully."
    flash[:notice] += "  It is awaiting moderation and will be posted soon." if !@comment.approved
    flash[:notice] += " <a href='#comment-#{@comment.id}'>Jump to it now.</a>" if @comment.approved
    session[:comment] = ""
    session[:comment_errors] = ""
    redirect_to @comment.referrer and return false
  else
    flash[:warning] = "There was a problem adding your comment. Check the comment form for more details."
    session[:comment] = params[:comment]
    session[:comment_errors] = @comment.error_message
    redirect_to @comment.referrer
  end
end

#destroyObject



23
24
25
26
27
28
29
30
# File 'lib/forge/app/controllers/comments_controller.rb', line 23

def destroy
  @comment = Comment.find(params[:comment_id])
  if logged_in? && current_user.staff?
    @comment.destroy
    flash[:notice] = "Comment deleted successfully."
  end
  redirect_to @comment.referrer
end