Class: CommentsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/comments_controller.rb', line 34

def create
  @comment = @commentable.comments.build(comment_params)
  if @comment.save
    trigger_events @comment
    CommentMailer.comment_notification(@comment).deliver_later
    if current_user.anonymous?
      flash.notice = "Your comment is being reviewed, and will be posted shortly. Thank you for commenting!"
    else
      @comment.update_column :approved, true
      flash.notice = "You're an admin, so your comment is being posted immediately! Refresh the page to see it."
    end
    respond_to do |format|
      format.html { redirect_to "#{request.env['HTTP_REFERER']}#comments" }
      format.js { render json: true }
    end
  else
    flash[:error] = @comment.errors.full_messages.to_sentence # TODO hu.
    respond_to do |format|
      format.html { redirect_to "#{request.env['HTTP_REFERER']}#comments" }
      format.js { render json: false }
    end
  end
end

#destroyObject



70
71
72
73
74
# File 'app/controllers/comments_controller.rb', line 70

def destroy
  @comment.destroy
  trigger_events @comment
  redirect_to "/", notice: t(:'adva.comments.flash.destroy.success')
end

#previewObject



28
29
30
31
32
# File 'app/controllers/comments_controller.rb', line 28

def preview
  @comment = @commentable.comments.build(comment_params)
  @comment.send(:process_filters)
  render :layout => false
end

#showObject



25
26
# File 'app/controllers/comments_controller.rb', line 25

def show
end

#updateObject



58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/comments_controller.rb', line 58

def update
  if @comment.update(comment_params)
    trigger_events(@comment)
    flash.notice = t(:'adva.comments.flash.update.success')
    render json: true
  else
    set_commentable
    flash[:error] = @comment.errors.full_messages.to_sentence
    render json: false
  end
end