class CommentsController < ApplicationController

  before_filter :require_login

  # Create comment.
  def create
    @comment = current_user.comments.build(comment_params)
    if @comment.save
      respond_to do |format|
        format.js
        format.json
      end
    else
      respond_to do |format|
        format.js {render partial: 'form', object: @comment}
      end
    end
  end

  # Destroy comment.
  def destroy
    @comment = current_user.comments.find(params[:id])
    @comment.destroy
    respond_to do |format|
      format.js
    end
  end


  private

    def comment_params
      params.require(:comment).permit(:body, :subject, :parent_id, :commentable_id, :commentable_type, :group_ids, attachments_attributes: [:attachment, :id, :_destroy])
    end

end
