Class: CommentsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#stored_location_for

Instance Method Details

#createObject


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

def create
  @comment = Comment.new(comment_params.merge(:user_id => current_user.id))
  if @comment.valid?
    @problem.comments << @comment
    @problem.save
    flash[:success] = "Comment saved!"
  else
    flash[:error] = "I'm sorry, your comment was blank! Try again?"
  end
  redirect_to app_problem_path(@app, @problem)
end

#destroyObject


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

def destroy
  @comment = Comment.find(params[:id])
  if @comment.destroy
    flash[:success] = "Comment deleted!"
  else
    flash[:error] = "Sorry, I couldn't delete your comment for some reason. I hope you don't have any sensitive information in there!"
  end
  redirect_to app_problem_path(@app, @problem)
end