我試圖通過使用CSV文件格式將一些批量的數據插入到表中的特定列。我的代碼如下:條件中的字符串文字
代碼:
def maritalstatus_migration
filename = "#{RAILS_ROOT}/config/MaritalStatus_Data_Migration_240114.csv"
file=File.new(filename,"r")
while (line = file.gets)
columns = line.split("$")
employee = Employee.find_by_employeeid(columns[0].to_s.chomp.strip)
personnel = Personnel.find_by_extid(columns[0].to_s.chomp.strip)
if employee && personnel
sheet_marital_status = columns[1].to_s.chomp.strip
if sheet_marital_status == 'Married' or 'MARRIED'
personnel.marital_status = 'Married'
elsif sheet_marital_status == 'Unmarried' or 'UNMARRIED'
personnel.marital_status = 'Unmarried'
elsif sheet.marital_status ='Unknown' or 'UNKNOWN'
personnel.marital_status = 'Unknown'
else
personnel.marital_status = columns[1].to_s.chomp.strip
end
end
end
end
當我在控制檯上運行我的方法,我得到一個警告說:
String literal in condition
指着線personnel.marital_status = columns[1].to_s.chomp.strip
,我算什麼我做錯了。任何建議將不勝感激。
這是完美的!謝謝。 – Pavan
感謝您的更正@Pavan –