[英]How can I have an “unread message” next to each message show in the inbox section of the mailbox?
Question: How can I have a 'Message not read' appear next to each message within my inbox? 问题:收件箱中的每封邮件旁边如何显示“未读邮件”?
I have created an internal mailing system for my app, using the mailboxer gem. 我已经使用信箱gem为我的应用程序创建了一个内部邮件系统。 My issue is when I go into the inbox section, and view all the messages that have been sent to my user account, I want to be able to see which messages I have not read.
我的问题是,当我进入“收件箱”部分并查看已发送到我的用户帐户的所有消息时,我希望能够看到哪些消息尚未阅读。
My code: 我的代码:
<div class="media-body">
<h4 class="media-heading">
<b> Sender: </b> <%= conversation.originator.username %> <br>
</h4>
<small><b>Subject: </b><%= conversation.subject %></small><br>
<small><b>Date: </b><%= conversation.messages.last.created_at.strftime("%A, %b %d, %Y at %I:%M%p") %></small><br>
<b> Recent message: </b> <%= truncate conversation.messages.last.body, length: 145 %>
<%= link_to "View", conversation_path(conversation) %>
</div>
This code works out, of the messages in the inbox, which ones are unread, and tallies them so I know which messages are not read. 此代码可计算收件箱中的哪些邮件未读,并对它们进行计数,以便我知道哪些邮件未读。
module MailboxHelper
def unread_messages_count
# how to get the number of unread messages for the current user
# using mailboxer
mailbox.inbox(:unread => true).count(:id, :distinct => true)
end
end
The only thing I can identify in the schema, that was generated by t he mailboxer gem, is the boolean is_read: 我在模式中唯一可以识别的,是邮箱的gem生成的,是布尔值is_read:
create_table "mailboxer_receipts", force: :cascade do |t|
t.integer "receiver_id"
t.string "receiver_type"
t.integer "notification_id", null: false
t.boolean "is_read", default: false
t.boolean "trashed", default: false
t.boolean "deleted", default: false
t.string "mailbox_type", limit: 25
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "is_delivered", default: false
t.string "delivery_method"
t.string "message_id"
end
I guess, based on this information, I'm unsure how to tie everything together so when I'm in the inbox view, and see all my messages, I want a "Not read" or something appearing for each message in the inbox. 我想根据这些信息,我不确定如何将所有内容捆绑在一起,因此当我在收件箱视图中并查看我的所有邮件时,我希望收件箱中的每封邮件都显示“未读”或显示内容。 How could I do this?
我该怎么办?
Also, what other information do you require? 另外,您还需要什么其他信息? The mailboxer gem generated a fair bit of code already, but I wasn't sure what is relevant to this question.
邮箱gem已经生成了相当多的代码,但是我不确定与这个问题有什么关系。
actually mailboxer has method in conversation record is_unread?(current_user) you can use it for your task above 邮箱实际上在对话记录is_unread中有方法吗?(current_user),您可以在上面的任务中使用它
below for example your conversations controller 下面例如您的对话控制器
@mailbox ||= current_user.mailbox
@conversations = @mailbox.inbox
in your view files (index_inbox.html.erb) 在您的视图文件(index_inbox.html.erb)中
<%= @conversations.each do |conversation| %>
# this to show subject that link to conversation
<%= link_to conversation.subject, conversation_path(conversation) %>
<% if conversation.is_unread?(current_user) %>
(unread message)
<% end %>
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.