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
上下文在它們創建後才能被查看/編輯。它僅對new
和create
操作是必需的。我把它像這樣:
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?
它的工作原理!謝謝。 –