Sha256: cb74deb1b267b7b5ac915d70b2d482072646b8ba6739f9c167e447825cad8f17
Contents?: true
Size: 1.36 KB
Versions: 10
Compression:
Stored size: 1.36 KB
Contents
# frozen_string_literal: true module Talkie class CommentsController < TalkieController before_action :current_comment, only: [:destroy] def create @comment = Talkie::Comment.new(comment_params) @comment.creator = current_user respond_to do |format| if @comment.save make_child_comment if reply? format.html { redirect_to Talkie.success_redirect_to.call(main_app, @comment.commentable), notice: t('talkie.controllers.comments.flash.success') } format.js else format.html { redirect_back fallback_location: Talkie.fail_redirect_to.call(main_app), notice: t('talkie.controllers.comments.flash.error') } format.js end end end def destroy current_comment.destroy redirect_to main_app.polymorphic_path(current_comment.commentable) end private def comment_params params.require(:comment).permit(:body, :commentable_id, :commentable_type, :mention_tokens) end def reply? params[:parent_comment_id].present? end def make_child_comment parent_comment = Comment.find params[:parent_comment_id] @comment.move_to_child_of(parent_comment) end def current_comment @current_comment ||= Talkie::Comment.find_by(id: params[:id]) end end end
Version data entries
10 entries across 10 versions & 1 rubygems