0

Итак у меня вылазит ошибка, при создании комментария к посту

Comments Controller

class CommentsController < ApplicationController

   def create
      @post = Post.find(params[:post_id])
      @comment = Post.comments.create(comment_params)
      redirect_to post_path(@post)
   end

   private def comment_params
      params.require(:comment).permit(:username, :body)
   end
end

Post rb

class Post < ApplicationRecord
   has_many :comments
   validates :title, presence: true, length: {minimum: 5}
end

Миграцию сделал, но всё-равно выводит ошибку

введите сюда описание изображения

1 ответ 1

0

У Вас ошибка в коде, Вы пытаетесь вызвать comments у класса Post, нужно вызывать у инстанса, который лежит в @post

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.