Custom rake task: uninitialized constant

Questo e’ un esempio di un rake taks ch mi sono fatto:

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 funziona perfettamente, l’import del file csv
viene fatto ma se faccio rake import:pericolanti
RAILS_ENV=“production” mi dice:
uninitialized constant UnsafeBuilding.
Come mai.

On 25 May 2011 08:22, Mauro [email protected] wrote:

return nil
if row.any?
intervention_date = parse_date_string(row[9])
rake import:pericolanti funziona perfettamente, l’import del file csv
viene fatto ma se faccio rake import:pericolanti
RAILS_ENV=“production” mi dice:
uninitialized constant UnsafeBuilding.
Come mai.

Scusate risolto, bisognava aggiungere require “/app/models/Model” nel
rake file.