這不是你如何傳遞一個對象的部分:如何將對象傳遞給部分?
<% @answers.each do |answer| %>
...
<%= render 'form_for_answer_comment', :answer => answer %> ?
<% end %>
我的部分看起來像:
<%= form_for([@question, @answer, @comment]) do |f| %>
我得到以下錯誤:
路由錯誤
No route matches {:action=>"create", :controller=>"questions/answers/comments", :format=>nil, :question_id=>#<Question id: 3, user_id: 1, title: "test", description: "asdfasdfasdfasdfasdfasdf\r\n\r\n\tasdfasd", created_at: "2011-09-10 01:33:38", updated_at: "2011-09-10 01:33:38">, :answer_id=>#<Answer id: nil, user_id: nil, question_id: nil, description: nil, selected: nil, created_at: nil, updated_at: nil>}
但是,它適用於:
<%= form_for([@question, Answer.first, @comment]) do |f| %>
我懷疑問題是它沒有正確傳遞@answer對象。我究竟做錯了什麼?
始終傳遞給諧音只有局部變量,而不是實例變量,就像你有。 –