Ruby初心者です。
独学で学んでおります。
Rubyにてコメントの削除覧を作成しています。
発生している問題・エラーメッセージ
NoMethodError in CommentsController#destroy
undefined method `comments' for nil:NilClass
Parameters:
{"_method"=>"delete",
"authenticity_token"=>"rR7+250lRlmV7hN7/BluLRjYpZu6VV/GSa9NIg1FO4WOdEOXmd9FtvMumpLfaTZAZJoCk11SDk8oolc7lSna7g==",
"article_id"=>"1",
"id"=>"6"}
自分の理解がまだ薄くどのように解決したら良いか調べても答えが出ません。。
どなたか詳しい方どうぞご教授いただきたく思います。
``
class CommentsController < ApplicationController def create # raise params.inspect @article = Article.find params[:article_id] @article.comments.create(comment_params) redirect_to article_path(@article) end def destroy #raise params.inspect @article = Article.find params[:article_id] @comment = @aritcle.comments.find params[:id] @comment.destroy redirect_to article_path(@article) end def comment_params params.require(:comment).permit(:commenter, :body) end end
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/24 05:48