0
我有意見屬於屬於問題的答案。我目前正試圖以顯示評論,但我得到一個錯誤:無法訪問雙重嵌套資源?
undefined method `comments' for nil:NilClass
從該行
顯然 <%=渲染@ answer.comments%>
我徵求意見的形式看起來像這樣
<%= form_for([@answer, @answer.comments.build]) do |f| %>
<p>
<%= f.label :comment %>
<%= f.text_area :comment, :cols => "50", :rows => "30"%>
</p>
<p>
<%= f.submit "Submit Comment" %>
</p>
而且我的意見控制器看起來像這樣
def create
@answer = Answer.find(params[:answer_id])
@comment = @answer.comments.create(params[:comment])
redirect_to answer_path(@answer)
end
評論belongs_to回答並回答has_many評論。謝謝!
仍然有一個未定義的方法錯誤,有什麼想法?謝謝! – google1254
什麼是你的params散列?您的控制器中有新的方法嗎? – rlecaro2
DEF創建 \t \t @comment = Comment.create(answer_id:PARAMS [:answer_id]) \t \t \t redirect_to的answer_path(@answer) \t年底 – google1254