To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / db / seeds.rb @ 912:5e80956cc792

History | View | Annotate | Download (797 Bytes)

1
# This file should contain all the record creation needed to seed the database with its default values.
2
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
#
4
# Examples:
5
#   
6
#   cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
#   Major.create(:name => 'Daley', :city => cities.first)
8

    
9
def truncate_table(table_name)
10
  quoted = connection.quote_table_name(table_name)
11
  connection.execute("TRUNCATE #{quoted}")
12
end
13

    
14
def connection
15
  ActiveRecord::Base.connection
16
end
17

    
18
truncate_table('institutions')
19

    
20
open("db/seed_data/institutions.txt") do |institutions|
21
  institutions.read.each_line do |institution|
22
    inst=institution.split('|')
23
    
24
    
25
    Institution.create(:name => inst[0].chomp, :order => inst[1].chomp)
26
  end
27
end