Sha256: 0f0e9f4d3326eddbb836a29e4f293679a87aede1b195c56eda06bc5f9270a39a
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
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 main_app.polymorphic_path(@comment.commentable), notice: "Comment was successfully added." } format.js else format.html { redirect_to :back, notice: "Something went wrong, blank comments are not allowed" } 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) 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
talkie-0.1.1 | app/controllers/talkie/comments_controller.rb |
talkie-0.1.0 | app/controllers/talkie/comments_controller.rb |