event = Event.find(4419)
user = event.created_by
index = 0
errors = []
attendee_type = AttendeeType.find(10230)
file_path = '/home/ubuntu/neiva.csv'
# file_path = '/Users/sherman/Desktop/bucaramanga.csv'
CSV.foreach(file_path , headers: true) do |row|
puts row
index += 1
import_columns = Hash[row.map{|header, value| [header.to_s.downcase.strip, value.to_s]}]
default_fields = {
attendee_type_id: attendee_type.id.to_s,
first_name: import_columns["first_name"].strip,
last_name: import_columns["last_name"].strip,
email: import_columns["email"].strip,
telephone: import_columns["telephone"].strip
}
attendee = Attendee.create_draft(event.id, user)
profile_company = "#{import_columns['first_name'].strip} #{import_columns['last_name'].strip}"
business_conference_participant = {
profile_display_name: profile_company,
location: import_columns["location"].strip
}
default_fields = {attendee: default_fields, business_conference_participant: business_conference_participant, network_registration: true, username: import_columns["email"].strip, password: "12345"}
puts default_fields
if !attendee.register(default_fields, user)
errors << "#{index + 1 }-#{import_columns["email"]}-#{attendee.errors.full_messages.join(',')}"
end
end