Sha256: 63f4c60bec69cbca6bc4b08e5ebbfae54de740717eebf5e16c3d1058ab7b328c

Contents?: true

Size: 589 Bytes

Versions: 2

Compression:

Stored size: 589 Bytes

Contents

require_dependency "personal_blog/application_controller"

module PersonalBlog
  class CommentsController < ApplicationController
    def create
      @post = Post.find(params[:post_id])
      @comment = @post.comments.create(comment_params)
      if @comment.valid?
        flash[:notice] = "Comment has been created!"
        redirect_to post_path(@post)
      else
        flash[:error] = "Comment must have some content."
        redirect_to post_path(@post)
      end
    end

    private
    def comment_params
      params.require(:comment).permit(:text, :author)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
personal_blog-0.0.2 app/controllers/personal_blog/comments_controller.rb
personal_blog-0.0.1 app/controllers/personal_blog/comments_controller.rb