I have an array of "names" and I would like to display the current user's name ONLY IF there it is the only name in the array. If there are other names in the array, I don't want to show the current user's name.
Currently, I am listing the names and excluding the current user's name, but don't want to exclude the current user's name if it is the only one in the array. I hope I explained that okay.
My code now:
module ConversationsHelper
def other_user_names(conversation)
users = []
conversation.messages.map(&:receipts).each do |receipts|
users << receipts.select do |receipt|
receipt.receiver != current_user
end.map(&:receiver)
end
users.flatten.uniq.map(&:name).join ', '
end
end