0

我正在向我的Questions模型添加评论,但遇到了错误。

查看页面时,我收到此错误:

undefined method `comments' for nil:NilClass

错误是由第 30 行引起的:

30: <% @question.comments.each do |comment| %>

不过,我无法弄清楚发生了什么。

我的控制器、模型和视图在这个 Gist中

你能帮帮我吗?

4

1 回答 1

0

您没有 @question 变量。像这样:

@question = Question.find(params[:question_id])

以你认为的正确方法 - 你没有写它是一个节目,或者可能是索引。

于 2013-06-03T22:41:26.720 回答