Sha256: 84c846c7e7f6cf1930f4d51587ce047fffdc90910a547fb921f8e20e65e80ddb

Contents?: true

Size: 843 Bytes

Versions: 4

Compression:

Stored size: 843 Bytes

Contents

class Comfy::Blog::CommentsController < Comfy::Blog::BaseController
  
  before_action :load_post,
                :build_comment
  
  def create
    @comment.save!
    
    flash[:success] = 'Comment created'
    redirect_to comfy_blog_post_path(@cms_site.path, @blog.path, @post.slug)
    
  rescue ActiveRecord::RecordInvalid
    flash[:error] = 'Failed to create Comment'
    render 'comfy/blog/posts/show'
  end

protected

  def load_post
    @post = @blog.posts.published.where(:slug => params[:slug]).first!
  rescue ActiveRecord::RecordNotFound
    flash[:error] = 'Blog Post not found'
    redirect_to comfy_blog_posts_path(@cms_site.path, @blog.path)
  end
  
  def build_comment
    @comment = @post.comments.new(comment_params)
  end

  def comment_params
    params.fetch(:comment, {}).permit(:author, :email, :content)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
comfy_blog-1.12.3 app/controllers/comfy/blog/comments_controller.rb
comfy_blog-1.12.2 app/controllers/comfy/blog/comments_controller.rb
comfy_blog-1.12.1 app/controllers/comfy/blog/comments_controller.rb
comfy_blog-1.12.0 app/controllers/comfy/blog/comments_controller.rb