Ruby on rails 我怎样才能有一个;“未读邮件”;在邮箱收件箱部分显示的每条邮件旁边?
问题:如何在收件箱中的每封邮件旁边显示“未阅读邮件” 我已经使用mailboxer gem为我的应用程序创建了一个内部邮件系统。我的问题是,当我进入收件箱部分,查看已发送到我的用户帐户的所有邮件时,我希望能够看到哪些邮件我没有阅读Ruby on rails 我怎样才能有一个;“未读邮件”;在邮箱收件箱部分显示的每条邮件旁边?,ruby-on-rails,ruby,mailboxer,Ruby On Rails,Ruby,Mailboxer,问题:如何在收件箱中的每封邮件旁边显示“未阅读邮件” 我已经使用mailboxer gem为我的应用程序创建了一个内部邮件系统。我的问题是,当我进入收件箱部分,查看已发送到我的用户帐户的所有邮件时,我希望能够看到哪些邮件我没有阅读 module MailboxHelper def unread_messages_count # how to get the number of unread messages for the current user # using mai
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
我的代码:
<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>
在由mailboxer 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
我想,基于这些信息,我不确定如何将所有内容联系在一起,因此当我在收件箱视图中查看所有邮件时,我希望收件箱中的每封邮件都显示“未阅读”或其他内容。我怎么能这样做
另外,您还需要哪些其他信息?mailboxer gem已经生成了相当多的代码,但我不确定什么与这个问题相关。实际上mailboxer在对话记录中有方法未读吗?(当前用户) 您可以将其用于上面的任务 下面举例说明您的对话控制器
@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 %>