【发布时间】:2014-08-19 18:49:34
【问题描述】:
将mailboxer gem 0.12.2 版与Rails 4.1.4 版一起使用。
当我向自己发送消息时,“对话”视图会显示相同的消息两次(一次是 mailbox_type=sentbox,一次是 mailbox_type=inbox)。我对发送给其他用户的消息没有这个问题。
我只想在我的对话视图中显示一次消息(理想情况下,查看我的收件箱时是 inbox 版本,查看我发送的消息时是 sentbox 版本。)有什么办法可以做到吗?
这是我的自定义ConversationsController 中的show 操作(current_user 是一种指示当前登录用户的设计方法)
def show
@mailbox = current_user.mailbox
@conversation = @mailbox.conversations.find(params[:id])
@receipts = @conversation.receipts_for(current_user)
end
我还在我的show 操作中尝试了以下组合,结果都相同。
- 使用
inbox方法代替conversations方法:@conversation = @mailbox.inbox.find(params[:id]) - 在
@mailbox实例变量上使用receipts_for方法:@receipts = @mailbox.receipts_for(@conversation)
这是我对应的show.html.erb 视图
<ul>
<%= content_tag_for(:li, @receipts) do |receipt| %>
<% message = receipt.message %>
<strong>From:</strong> <%= message.sender.email %>
<br/>
<strong>Message:</strong><%= simple_format h message.body %>
<strong>Sent:</strong> <%= @conversation.updated_at.strftime("%a, %m/%e/%Y %I:%M %p") %>
<div>
<br/>DEBUG INFO:<br/>
Message Id <%= message.id %><br/>
Receipt Id <%= receipt.id %><br/>
Receipt Mailbox type <%= receipt.mailbox_type %><br/>
</div>
<hr/>
<% end %>
</ul>
有没有办法让我的“收件箱”视图用于与我自己的对话而不显示重复的消息?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 mailboxer