如何在邮箱的收件箱部分显示每条消息旁边的 "unread message"?
How can I have an "unread message" next to each message show in the inbox section of the mailbox?
问题:如何在收件箱中的每封邮件旁边显示 'Message not read'?
我使用邮箱 gem 为我的应用程序创建了一个内部邮件系统。我的问题是,当我进入收件箱部分并查看已发送到我的用户帐户的所有邮件时,我希望能够查看哪些邮件我没有阅读。
我的代码:
<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>
此代码计算出收件箱中的哪些邮件未读,并统计它们以便我知道哪些邮件未读。
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
我在架构中唯一可以识别的东西,是由邮箱 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
我想,根据这些信息,我不确定如何将所有内容联系在一起,所以当我在收件箱视图中查看我的所有邮件时,我想要一个 "Not read" 或显示的内容收件箱中的每条消息。我该怎么做?
此外,您还需要什么其他信息?邮箱 gem 已经生成了一些代码,但我不确定什么与这个问题相关。
其实mailboxer在会话记录里有方法is_unread?(current_user)
你可以用它来完成上面的任务
下面是您的对话控制器
@mailbox ||= current_user.mailbox
@conversations = @mailbox.inbox
在您的视图文件中 (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 %>
问题:如何在收件箱中的每封邮件旁边显示 'Message not read'?
我使用邮箱 gem 为我的应用程序创建了一个内部邮件系统。我的问题是,当我进入收件箱部分并查看已发送到我的用户帐户的所有邮件时,我希望能够查看哪些邮件我没有阅读。
我的代码:
<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>
此代码计算出收件箱中的哪些邮件未读,并统计它们以便我知道哪些邮件未读。
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
我在架构中唯一可以识别的东西,是由邮箱 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
我想,根据这些信息,我不确定如何将所有内容联系在一起,所以当我在收件箱视图中查看我的所有邮件时,我想要一个 "Not read" 或显示的内容收件箱中的每条消息。我该怎么做?
此外,您还需要什么其他信息?邮箱 gem 已经生成了一些代码,但我不确定什么与这个问题相关。
其实mailboxer在会话记录里有方法is_unread?(current_user) 你可以用它来完成上面的任务
下面是您的对话控制器
@mailbox ||= current_user.mailbox
@conversations = @mailbox.inbox
在您的视图文件中 (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 %>