Search code examples
ruby-on-rails-3mailboxer

mailboxer - get recipient of a message


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?


Solution

  • 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.