annotate db/seeds.rb @ 922:ad295b270cd4 live

FIx #446: "non-utf8 paths in repositories blow up repo viewer and reposman" by ensuring the iconv conversion always happens even if source and dest are intended to be the same encoding
author Chris Cannam
date Tue, 13 Mar 2012 16:33:49 +0000
parents 5b074cadc4d1
children
rev   line source
luis@98 1 # This file should contain all the record creation needed to seed the database with its default values.
luis@98 2 # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
luis@98 3 #
luis@98 4 # Examples:
luis@98 5 #
luis@98 6 # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
luis@98 7 # Major.create(:name => 'Daley', :city => cities.first)
luis@98 8
luisf@179 9 def truncate_table(table_name)
luisf@179 10 quoted = connection.quote_table_name(table_name)
luisf@179 11 connection.execute("TRUNCATE #{quoted}")
luisf@179 12 end
luisf@179 13
luisf@179 14 def connection
luisf@179 15 ActiveRecord::Base.connection
luisf@179 16 end
luisf@179 17
luisf@179 18 truncate_table('institutions')
luisf@179 19
luis@98 20 open("db/seed_data/institutions.txt") do |institutions|
luis@98 21 institutions.read.each_line do |institution|
luisf@182 22 inst=institution.split('|')
luisf@182 23
luisf@182 24
luisf@182 25 Institution.create(:name => inst[0].chomp, :order => inst[1].chomp)
luis@98 26 end
luis@98 27 end