Err in Documentation

4 views
Skip to first unread message

Tyler Harpool

unread,
Nov 14, 2013, 1:20:20 AM11/14/13
to rubyonra...@googlegroups.com
You forgot to update Strong params in section 6.4 (deleting comments)  http://guides.rubyonrails.org/getting_started.html

This is your final code:


class CommentsController < ApplicationController
 
  def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(params[:comment])
    redirect_to post_path(@post)
  end
 
  def destroy
    @post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:id])
    @comment.destroy
    redirect_to post_path(@post)
  end
 
end

It should be:

class CommentsController < ApplicationController
 
  def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(params[:comment].permit(:commenter, :body))
    redirect_to post_path(@post)
  end
 
  def destroy
    @post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:id])
    @comment.destroy
    redirect_to post_path(@post)
  end
 
end
Reply all
Reply to author
Forward
0 new messages