Class: PersonalBlog::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/personal_blog/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/personal_blog/comments_controller.rb', line 5

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

#destroyObject



17
18
19
20
21
22
# File 'app/controllers/personal_blog/comments_controller.rb', line 17

def destroy
  @post = Post.find(params[:post_id])
  @comment = @post.comments.find(params[:id])
  @comment.destroy
  redirect_to post_path(@post), notice: "Comment was successfully destroyed."
end