I can get the last sender of a message:

conversation.receipts_for(current_user).last.message.sender.name

but cannot get the recipient(s) of that same message. I would like to display gmail-esk:

Sender name, Recipient name | Subject | Date

Any ideas?

有帮助吗?

解决方案 2

I created this method in a helper file:

  def participant_names(conversation)
    conversation.receipts.reject { |p| p.receiver == current_user }.collect {|p| p.receiver.name }.uniq.join(" ,")
  end

What this is doing is, removing the current_user from the conversation object, then creates a new array that contains the names for (in this case users) that conversation object. the '.uniq' method ensures that each users name is only displayed once (in the case there have been many message back and forth conversation). Finally comma separates them.

其他提示

There is a participants method with mailboxer, but I believe there is no recipient(s). Instead, I created this:

recipient = conversation.participants.find { |p| p != current_user }

Note that current_user comes from devise.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top