Add seeding task and data for the State model

parent 623edc6a
id;nome;fk_regiao_id
11;Rondônia;1
12;Acre;1
13;Amazonas;1
14;Roraima;1
15;Pará;1
16;Amapá;1
17;Tocantins;1
21;Maranhão;2
22;Piauí;2
23;Ceará;2
24;Rio Grande do Norte;2
25;Paraíba;2
26;Pernambuco;2
27;Alagoas;2
28;Sergipe;2
29;Bahia;2
31;Minas Gerais;3
32;Espírito Santo;3
33;Rio de Janeiro;3
35;São Paulo;3
41;Paraná;4
42;Santa Catarina;4
43;Rio Grande do Sul;4
50;Mato Grosso do Sul;5
51;Mato Grosso;5
52;Goiás;5
53;Distrito Federal;5
......@@ -30,6 +30,26 @@ namespace :db do
task seed_states: [ :environment, :seed_regions ] do
print "Seeding states..."
states_csv = Rails.root.join("db/seeds_csv/states.csv").to_s
def map_states(csv_header)
map = Array.new
csv_header.each do |hval|
# map header value to model field
mval = case hval
when "id" then "id"
when "nome" then "name"
when "fk_regiao_id" then "region_id"
else ""
end
# push mapped value to map
map.push mval
end
return map
end
import_csv(states_csv, State, :map_states)
print "OK\n"
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment