@followers = current_user.followers.joins(:received_messages).uniq.order("id DESC")
快速解释,它抓取当前用户的关注者并将他们与消息一起发送/接收。并且一次只显示一个。
我正在使用它来显示收件箱中的“消息”,该部分工作正常,我想通过最新发送或接收的消息 ID 订购该收件箱。
现在我的视图看起来像这样,(这真是一团糟,我知道有一些方法可以让我在 ruby 中做到更清洁)
-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)