2013-10-24 34 views
0

我有3個模型:帖子,評論和問題。我試圖在問題索引頁面上顯示問題所屬帖子的標題。從某種意義上講,通過資源回溯。 這裏是什麼路線是這樣的:在嵌套資源中倒退

resources :posts do 
resources :comments do 
end 
end 

resources :comments do 
resources :questions do 
end 
end 

眼下我這是如何試圖做到這一點在我的問題,索引頁,但我得到一個「未定義的方法標題錯誤」:

<% @post.title %> 

謝謝!

回答

1

似乎,@post是無問題索引頁。路由只是幫助路由,嵌套應通過has_manybelongs_to在模型內連線。

「回到」嘗試@question.post.title

順便說一句,你在Post模型有標題字段?

+0

好的,謝謝,我明白了。我不得不和你一起玩一下,<%= @ comment.post.title%>最終還是做了個伎倆。謝謝您的幫助! – user2759575