class CommentsController < ApplicationController allow_unauthenticated_access before_action :set_member before_action :set_blog before_action :set_post def create @comment = @post.comments.build(comment_params) if @comment.save redirect_to member_blog_post_path(@member, @blog, @post), notice: "Comment added!" else redirect_to member_blog_post_path(@member, @blog, @post), alert: "Could not save comment." end end def destroy @comment = @post.comments.find(params[:id]) @comment.destroy redirect_to member_blog_post_path(@member, @blog, @post), notice: "Comment deleted." end private def set_member @member = Member.find(params[:member_id]) end def set_blog @blog = @member.blogs.find(params[:blog_id]) end def set_post @post = @blog.posts.find(params[:post_id]) end def comment_params params.require(:comment).permit(:commenter, :website, :body) end end