トピックに対してコメントが出来るようなアプリケーションを作っています、
トピックあたりのコメント数を数えたくてTopicテーブルにcomsというカラムを追加しました
def comment @topic=Topic.find(params[:topic_id]) @comment = Comment.new(comment_params) if @comment.save @com=@topic.coms @com+=1 @topic.update(coms:@com) redirect_to(:back) else render 'show' end end def comment_params params[:comment]["ip"]=request.remote_ip require(:comment).permit(:name,:text,:topic_id,:ip) end
としたのですが
@topicid=Topic.find(params[:topic_id])に対してActiveRecord::RecordNotFound in TopicsController#comment
Couldn't find Topic with 'id'=というエラーがでてしまいました。
どうすれば解決できるでしょうか
エラー全文を正しく(ソースコードと同様の形で)ご提示ください。
あなたの回答
tips
プレビュー