Class: CommentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject


9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/comments_controller.rb', line 9

def create
  @commentable = find_commentable
  @comment = @commentable.comments.build(comment_params)
  @comment.user = current_user
  if @comment.save
    flash[:notice] = "You successfully added a comment for #{@commentable.class.name} #{@commentable.id}"
    redirect_to id: nil
  else
    raise 'something went wrong'
  end
end

#indexObject


4
5
6
7
# File 'app/controllers/comments_controller.rb', line 4

def index
  @commentable = find_commentable
  @comments = @commentable.comments
end