Skip to content

Instantly share code, notes, and snippets.

@sergiogomez
Created July 21, 2009 11:58
Show Gist options
  • Save sergiogomez/151303 to your computer and use it in GitHub Desktop.
Save sergiogomez/151303 to your computer and use it in GitHub Desktop.
Carga de fixtures csv con campos NULL
# Adaptación del código de Emili Parreño para cargar fixtures csv [1]
# con la gema fastercsv para los campos NULL [2]
# [1] http://gist.github.com/151213
# [2] http://www.kahfei.com/?p=32
require 'fastercsv'
namespace :db do
namespace :import do
task :sections => :environment do
puts "Importando secciones de la aplicación..."
FasterCSV.foreach(Rails.root + "/db/import/sections.csv") do |row|
record = Section.new(
:name => row[0],
:section_id => row[1],
:section_order => row[2]
)
record.save
end
end
task :all => :environment do
Rake::Task['db:import:sections'].execute
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment