Sha256: 6137ef6cbb9cc8e2abf2c67ecf8767d0d3e354d451659cbf27ed6b51964cdce9

Contents?: true

Size: 811 Bytes

Versions: 3

Compression:

Stored size: 811 Bytes

Contents

class Blog::CommentsController < Blog::BaseController
  
  before_action :load_post,
                :build_comment
  
  def create
    @comment.save!
    
    flash[:success] = 'Comment created'
    redirect_to blog_post_path(@cms_site.path, @blog.path, @post.slug)
    
  rescue ActiveRecord::RecordInvalid
    flash[:error] = 'Failed to create Comment'
    render '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 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

3 entries across 3 versions & 1 rubygems

Version Path
comfy_blog-1.1.1 app/controllers/blog/comments_controller.rb
comfy_blog-1.1.0 app/controllers/blog/comments_controller.rb
comfy_blog-1.0.0 app/controllers/blog/comments_controller.rb