0
게시 모델에 주석을 추가하려고합니다. 나는이 오류가덧글을 작성하는 방법
class CommentsController < ApplicationController
before_action :find_post
def index
@comments = @post.comments.order('id')
end
def new
@comment = @post.comments.new
end
def create
@comment = @post.comments.build(params[:comment])
@comment.user = current_user
@comment.save
redirect_to post_path(@post)
end
private
def comment_params
params.require(:comment).permit(:comment_body)
end
def find_post
@user = current_user
@post = @user.posts.find(params[:post_id])
end
end
:이 지금까지 내 comments_controller입니다
NoMethodError in CommentsController#new undefined method `posts' for nil:NilClass
당신은 내가 프로그래밍에 새로 온 사람을 볼 수 있습니다. 도움을 주셔서 감사합니다! :)
예! 고맙습니다 :) – fuskie