加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 20:17:06 所属栏目:百科 来源:网络整理
导读:我正在使用邮箱程序gem与我的rails应用程序,我想订购我的收件箱消息,以便当用户收到一条新消息时,我想要通知或跟踪哪些消息已被读取,哪些没有和没有订购消息在页面顶部具有未读/新消息. 这是我的对话控制器 class ConversationsController ApplicationContro
我正在使用邮箱程序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时,您实际上是拉最后一条(最新)消息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读