メールボックスの gem バージョン 0.12.2 を Rails バージョン 4.1.4 で使用する。
自分自身にメッセージを送信すると、会話ビューに同じメッセージが 2 回表示されます (1 回はmailbox_type
=としてsentbox
、もう 1 回はmailbox_type
=としてinbox
)。他のユーザーに送信されたメッセージにはこの問題はありません。
メッセージを会話ビューで一度表示したいだけです (理想的にはinbox
、受信トレイを表示するsentbox
ときのバージョンと、送信済みメッセージを表示するときのバージョンです)。それを行う方法はありますか?
これが私show
のカスタムでのアクションですConversationsController
(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])
- インスタンス変数
receipts_for
でメソッドを使用する:@mailbox
@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>
重複したメッセージを表示しないように、自分との会話の「受信トレイ」ビューを取得する方法はありますか?