i have changed my db tu utf8-general-ci, when i edit or create an employee
throught the site and i fill in "jéan", in the database comes
"jéan".
when i want to import that through csv, it is fucked up, this is the file:
Firstname;Lastname;Phone;Phone Pin
Jan;Klaas;3259778899;5555
Jéan;Klaas;3259778888;5556
;Vandevelde;3259452145;0010
Stijn;;;
i get this as output for the user(correct):
Check There were errors on these records, there were not added to the database.
Import Employees
Row 4: , Vandevelde, , 0010
* First name can''t be blank
Row 5: , , , 0000
* First name can''t be blank
* Last name can''t be blank
Row 6: Stijn, , , 0000
* Last name can''t be blank
this is my code:
def upload
fileupload = @params[:file]
@msg = ""
errors = false
if fileupload.original_filename.slice(-3..-1) != "csv"
@msg = "Please only upload .csv files."
else
filename = rand(9999999999).to_s.rjust(10,"0") + ".csv"
folder = "C:/temp/"
while FileTest.file?(folder + filename)
filename = rand(9999999999).to_s.rjust(10,"0") + ".csv"
end
File.open(folder + filename, "wb") { |f| f.write(fileupload.read) }
csv_file_path = folder + filename
firm_id = @session[:user].firm_id
#CSV READING
@first = true #skip first row (headers)
row_number = 2
CSV.open(csv_file_path, ''r'') do |row|
# use row here...
if @first
@first = false
else
error = false
errormsg = ""
cells = Array.new
cells = row.to_s.split('';'')
if cells != nil
first_name = cells[0].nil? ? '''' : cells[0]
last_name = cells[1].nil? ? '''' : cells[1]
phone = cells[2].nil? ? '''' : cells[2]
phone_pin = cells[3].nil? ? '''' : cells[3]
#Validate values
phone_pin = phone_pin.to_s.rjust(4,"0")
@temp= Employee.new
#SETING THE VALUES TO THE OBJECT
@temp.first_name = first_name
@temp.last_name = last_name
@temp.phone = "+" + phone.to_s
@temp.phone_pin = phone_pin
#SAVING THE OBJECT
if @temp.save
else
errors = true
err = parse_errors(@temp)
@msg += "Row " + row_number.to_s + ": "
+ first_name + ", " + last_name +
", " +
phone + ", " + phone_pin + "<br/>" +
err + "<br/>"
end
end
row_number += 1
end
end
if errors
flash[:notice] = "There were errors on these records, there were not added
to
the database."
else
flash[:notice] = "All records succesfully added to the database."
end
end
---------------------
Jan;Klaas;3259778899;5555
Jéan;Klaas;3259778888;5556
this should be in the db but i get:
Jan;Klaas;;5555
J;Klaas;;5556
can anyone help me?
thanks