ruby-on-rails – 如何订购邮箱收件箱?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 如何订购邮箱收件箱?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用邮箱程序gem与我的rails应用程序,我想订购我的收件箱消息,以便当用户收到一条新消息时,我想要通知或跟踪哪些消息已被读取,哪些没有和没有订购消息在页面顶部具有未读/新消息.

这是我的对话控制器

class ConversationsController < ApplicationController
  before_action :get_mailBox
  before_action :get_conversation,except: [:index]

  def index
    @unread_messages = @mailBox.inBox(unread: true).count
    @conversations = @mailBox.inBox({page: params[:page],per_page: 10})
  end

  private

  def get_conversation
    @conversation ||= @mailBox.conversations.find(params[:id])
  end

  def get_mailBox
    @mailBox ||= current_user.mailBox
  end
end

我试图通过以下方式订购邮件

@conversations = @mailBox.inBox({page: params[:page],per_page: 10}).joins(:receipts).select("mailBoxer_conversations.*,mailBoxer_receipts.*").order('mailBoxer_receipts.is_read')

但它没有奏效.

请建议一个解决方案.

解决方法

尝试这个,
def index
  @unread_messages = @mailBox.inBox(is_read:false).count
  @conversations = @mailBox.inBox.page(params[:page]).per(10)
end

并且默认情况下,收件箱被排序以显示顶部的最新消息,例如当您键入@ mailBox.inBox.first时,您实际上是拉最后一条(最新)消息.

原文链接:https://www.f2er.com/ruby/273061.html

猜你在找的Ruby相关文章