我正在使用宝石mailboxer 谁能告诉我如何计算收件箱中未读邮件的数量?
我试过了:
<%= current_user.mailbox.inbox.unread.count %>
但我得到
'ArgumentError in Messages#received wrong number of arguments (0 for 1)'
答案 0 :(得分:4)
版本0.10:
@user.mailbox.receipts.where(read:false).count
版本0.11,我认为(很难,我没有测试过它)
@user.mailbox.receipts.where(is_read:false).count
答案 1 :(得分:2)
看看@MurifoX提供的源代码链接,我发现了有关未读方法的信息:
current_user.unread_inbox_count
为您提供未读邮件收件箱数。
答案 2 :(得分:1)
看一下源代码,我发现了unread
方法:
#Mark the object as unread for messageable.
def unread(obj)
...
end
所有这些方法都将邮件/邮件标记为未读,以便检索所有未读邮件
在课堂上我找到了这个可能与你的问题有关的def search_messages(query)
方法。
链接到班级。 https://github.com/ging/mailboxer/blob/master/lib/mailboxer/models/messageable.rb
答案 3 :(得分:1)
我使用0.9.x
的版本mailboxer
。他们将相应的数据库字段从read
重命名为is_read
。要计算用户的未读消息,只需使用:
@user.mailbox.receipts.where(:is_read => false).count
答案 4 :(得分:0)
对我而言,这个效果最好:
current_user.mailbox.inbox(:unread => true).count(:id, :distinct => true)