게시물, 질문 및 의견 (질문에 포함 된 주석은 게시물에 속해 있음) 및 의견 색인 페이지에서 마지막 두 가지 질문을 표시하려고합니다. 여기 정의되지 않은 메서드 'questions'
<% @questions.each do |question| %>
<%= question.body %>
<% end %>
내가 점점 오전 오류입니다 :
def index
@question = Question.find params[:question_id]
@comments = @question.comments
@questions = @comment.questions.order(:created_at).limit(2).reverse_order
end
내 comments_index :
가 여기 내 comments_index 기능입니다
undefined method `questions' for nil:NilClass
내 routes.rb 파일은 다음과 같습니다 :
resources :posts do
resources :questions do
end
end
resources :questions do
resources :comments do
end
end
게시물에 속한 마지막 2 개의 질문이되기를 바란다. 미안하지만 내가 충분히 명확하지 않았다면. 네가 내 길에 대해 옳다고 생각해. 내가 바꿀거야. – user2759575
so ...'@ question.post.questions.order (: created_at) .last (2)'. 보기에서 사용할 인스턴스 변수로'@ post '를 가져오고 싶을 수도 있습니다. 그래서 ...'@post = @ question.post'. @ post.questions 등 – Dudo