Sha256: 38a54c3bcbdfbf6ca980629ad56d65720ad63e77eb0eb419735cffa8cc571357

Contents?: true

Size: 941 Bytes

Versions: 4

Compression:

Stored size: 941 Bytes

Contents

require_dependency "storytime/application_controller"

module Storytime
  class CommentsController < ApplicationController
    before_action :authenticate_user!
    after_action :verify_authorized

    before_action :set_post, only: :create

    respond_to :json, only: :destroy

    def create
      @comment = Comment.new(comment_params)
      @comment.user = current_user
      @comment.post = @post

      authorize @comment
      opts = { notice: I18n.t('flash.comments.create.success') } if @comment.save
      redirect_to @post, opts
    end

    def destroy
      @comment = current_user.storytime_comments.find(params[:id])
      authorize @comment
      @comment.destroy
      respond_with @comment
    end

  private

    def set_post
      @post = Post.friendly.find(params[:post_id])
    end

    def comment_params
      params.require(:comment).permit(*policy(@comment || Comment.new).permitted_attributes)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
storytime-1.2.0 app/controllers/storytime/comments_controller.rb
storytime-1.1.1 app/controllers/storytime/comments_controller.rb
storytime-1.0.7 app/controllers/storytime/comments_controller.rb
storytime-1.0.6 app/controllers/storytime/comments_controller.rb