我正在关注有关如何为我的Rails应用实施评论的教程,用户可以为帖子添加评论。但是,当我单击“添加新评论”时,我收到“ Reviews#new中的NoMethodError”
评论控制器
class Review < ApplicationRecord
belongs_to :post
belongs_to :user
end
评论模型
class Post < ApplicationRecord
extend FriendlyId
belongs_to :user
friendly_id :title, use: :slugged
validates_presence_of :title , :description
end
帖子模型
DateTimeFormatter
答案 0 :(得分:1)
您似乎在has_many :reviews
模型中忘记了Post
。