From 29da04d51f744becb5219a9366a3105a09c4f610 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sun, 9 Oct 2016 05:30:25 +0300 Subject: [PATCH] Display email-friendly names and emails in events csv export --- app/helpers/events_helper.rb | 9 ++++++--- app/views/management/events/index.csv.erb | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 75d08ac..74423a3 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -14,11 +14,14 @@ module EventsHelper end.join(', ').html_safe end - def participant_names_or_emails(event) + def participant_names_with_emails(event) event.participants.map do |participant| - participant.try(:personal_profile, current_conference).try(:name) || - participant.personal_profiles.last.try(:name) || + if participant.personal_profile(event.conference).present? + profile = participant.personal_profile(event.conference) + "#{profile.name} <#{participant.email}>" + else participant.email + end end end end diff --git a/app/views/management/events/index.csv.erb b/app/views/management/events/index.csv.erb index 1a04c93..fd2e0c9 100644 --- a/app/views/management/events/index.csv.erb +++ b/app/views/management/events/index.csv.erb @@ -1,5 +1,5 @@ <%- csv_headers = %w{id title subtitle type track language paticipants status} -%> <%= CSV.generate_line(csv_headers).html_safe -%> <%- @events.each do |event| -%> - <%= CSV.generate_line([event.id, event.title, event.subtitle, event.event_type.name, event.track.name, event.language, participant_names_or_emails(event).join(', '), event.status]).html_safe -%> + <%= CSV.generate_line([event.id, event.title, event.subtitle, event.event_type.name, event.track.name, event.language, participant_names_with_emails(event).join(', '), event.status]).html_safe -%> <%- end -%>