I have this rake taks:
CUSTOM_MONTHS = [nil, "GEN", "FEB", "MAR", "APR", "MAG", "GIU", "LUG", "AGO", "SET", "OTT", "NOV", "DIC"]
def parse_date_string(date_string) begin day, month, year = date_string.split("-") Time.mktime(year, CUSTOM_MONTHS.index(month), day).strftime("%Y-%m-%d") rescue return nil end end
namespace :import do desc 'import pericolanti' task :pericolanti => :environment do UnsafeBuilding.delete_all puts "Creating unsafe_buildings..." lines = FasterCSV.read('/home/user/Docs/pericolanti') lines.each do |row| if row.any? # controllo che row[10] e row[11] non siano stringhe barrier_meters = row[10] if row[10].is_a?(Float) or row[10].is_a?(Integer) square_meters_public_land = row[11] if row[11].is_a?(Float) or row[11].is_a?(Integer)
practice_number = row[17].to_i practice_date = parse_date_string(row[3]) practice_new_date = parse_date_string(row[3]) inspection_date = parse_date_string(row[7]) intervention_date = parse_date_string(row[9]) remove_date = parse_date_string(row[13]) notification_date = parse_date_string(row[14]) expiry_date = parse_date_string(row[15]) cordoned_off = true if row[8] == "Si" or row[8] == "SI" cordoned_off = false if row[8] == "No" or row[8] == "NO" UnsafeBuilding.create!({ :practice_number => practice_number, :address => row[6]
etc. etc.
rake import:pericolanti works well but if I do rake import:pericolanti RAILS_ENV="production" it says: uninitialized constant UnsafeBuilding. Why?