Created
July 21, 2009 11:58
-
-
Save sergiogomez/151303 to your computer and use it in GitHub Desktop.
Carga de fixtures csv con campos NULL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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