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
にのみ必要です。私は次のように設定しました:new
create
resources :message_threads, :only => [:show, :destroy]
resources :listings do
resources :message_threads, :only => [:new, :create]
end
アクションビューのform_for
構文を理解できないようです...私は理解していますが、それは機能していません。これは、このオブジェクトを設定する正しい方法ですか? ルートをネストするのではなく、リスティング ID を URL のパラメーターとして渡す必要がありますか? または、リストの下にある message_thread を常に参照しますか?new
MessageThreadsController
form_for @message_thread