@followers = current_user.followers.joins(:received_messages).uniq.order("id DESC")
快速解釋,它抓住當前用戶的關注者,並將它們與消息一起發送/接收。並且一次只顯示一個。試圖加入兩個表格,並顯示正確的信息
我用這個來顯示收件箱中的'消息'部分工作正常,我想通過最新發送或收到的消息ID訂購該收件箱。
現在我的看法是這樣的,(這是一個混亂的地獄,我知道有一些辦法,我做清潔的紅寶石)
-if f.sent_messages.first && f.received_messages.first
-if f.sent_messages.last.id > f.received_messages.last.id
p This is running
=image_tag f.avatar
h2= f.uid
p= f.sent_messages.last.body
=link_to "Go To Conversation", conversation_path(:id => f.sent_messages.last.sender_id)
-else
=image_tag f.avatar
h2= f.uid
p= f.received_messages.last.body
=link_to "Go To Conversation", conversation_path(:id => f.received_messages.last.receiver_id)
end
-elsif f.sent_messages.first && f.received_messages.first == nil
=image_tag f.avatar
h2= f.uid
p= f.sent_messages.last.body
=link_to "Go To Conversation", conversation_path(:id => f.sent_messages.last.sender_id)
-elsif f.sent_messages.first == nil && f.received_messages.first
=image_tag f.avatar
h2= f.uid
p= f.received_messages.last.body
=link_to "Go To Conversation", conversation_path(:id => f.received_messages.last.receiver_id)
我有這個大規模elsif聲明的原因是因爲如果其中一個用戶沒有發送或收到此類別的郵件,它會打破頁面。 –