2011-11-15 45 views
0

在我的Rails網站上,用戶發佈了他們想銷售的商品Listings。其他用戶可以瀏覽這些列表和點擊一個鏈接與賣家聯繫,這應該創建一個MessageThread如何設置部分嵌套的足智多謀的路線?

# MessageThread properties... 
listing_id 
poster_id # (listing_id's owner.. this is a shortcut for to avoid joins on the database) 
sender_id 
body # (text of message) 

MessageThreads從來沒有一個Listing的上下文之外創建的,所以我嵌套他們足智多謀的路線。但是,它們不需要Listing上下文在它們創建後才能被查看/編輯。它僅對newcreate操作是必需的。我把它像這樣:

resources :message_threads, :only => [:show, :destroy] 

resources :listings do 
    resources :message_threads, :only => [:new, :create] 
end 

我似乎無法找出在new行動鑑於form_for語法爲MessageThreadsController ...我form_for @message_thread但不工作。這是設置這個對象的正確方法嗎?我是否應該避免使用足智多謀的路線,或者可以將列表ID作爲URL中的參數傳遞,而不是嵌套路線?或者總是引用列表下的message_thread?

回答

1

這應該工作:

form_for @message_thread, :url => listing_message_threads_path(@listing) 

你總是可以在命令行

rake routes | grep message_thread 

運行這個新的鏈接將

new_listing_message_threads_path(@listing) 
+0

它的工作原理!謝謝。 –

相關問題