0

Listings私の Rails サイトでは、ユーザーが売りたい商品を投稿します。他のユーザーはこれらのリストを閲覧し、リンクをクリックして販売者に連絡できます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

アクションビューのform_for構文を理解できないようです...私は理解していますが、それは機能していません。これは、このオブジェクトを設定する正しい方法ですか? ルートをネストするのではなく、リスティング ID を URL のパラメーターとして渡す必要がありますか? または、リストの下にある message_thread を常に参照しますか?newMessageThreadsControllerform_for @message_thread

4

1 に答える 1

1

これは機能するはずです:

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

これはいつでもコマンドラインで実行できます

rake routes | grep message_thread

新しいリンクは

new_listing_message_threads_path(@listing)
于 2011-11-16T03:50:46.233 に答える