Sha256: 0c841da691a76b57f523d13cbafeae04104b51d71e1d049ea113d9ce2ac94796

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

require_dependency "almanac/application_controller"

module Almanac
  class CommentsController < ApplicationController
    load_and_authorize_resource class: Almanac::Comment
    respond_to :html

    def create
      @comment = Comment.new(params[:comment])
      @post = Post.find(params[:post_id])

      @comment.post = @post

      respond_with(@comment) do |format|
        @comment.spam = (@blog.rakismet_key?) ? @comment.spam? : false

        if @comment.save
          format.html {
            redirect_to post_path(@post.slug),
                        :notice => (@comment.spam) ? "Your comment looks like spam, it won't be published." : "Comment was successfully posted."
          }
        else
          format.html { redirect_to post_path(@post.slug), :alert => 'Something went wrong, try again.' }
        end
      end
    end

    def destroy
      @post = Post.find(params[:post_id])
      @comment = Comment.find(params[:id])
      respond_to do |format|
        if @comment.destroy
          format.html { redirect_to post_path(@post), :notice => 'Comment was successfully deleted.' }
          format.js { render :nothing => true }
        else
          format.html { redirect_to post_path(@post), :alert => 'Something went wrong, try again.' }
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
almanac-0.7.4 app/controllers/almanac/comments_controller.rb
almanac-0.7.3 app/controllers/almanac/comments_controller.rb
almanac-0.7.2 app/controllers/almanac/comments_controller.rb
almanac-0.7.1 app/controllers/almanac/comments_controller.rb
almanac-0.6.1 app/controllers/almanac/comments_controller.rb