Permalink
Browse files

add generators and change install.rb

  • Loading branch information...
flyerhzm committed Jul 26, 2009
1 parent 6ea212e commit 039ecaa788be045d3e2720e98e9c27499f68efff

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,43 @@
+class CreateRegions < ActiveRecord::Migration
+ def self.up
+ create_table :regions do |t|
+ t.string :name
+ end
+
+ Region.create(:name => '北京市')
+ Region.create(:name => '天津市')
+ Region.create(:name => '河北省')
+ Region.create(:name => '山西省')
+ Region.create(:name => '内蒙古自治区')
+ Region.create(:name => '辽宁省')
+ Region.create(:name => '吉林省')
+ Region.create(:name => '黑龙江省')
+ Region.create(:name => '上海市')
+ Region.create(:name => '江苏省')
+ Region.create(:name => '浙江省')
+ Region.create(:name => '安徽省')
+ Region.create(:name => '福建省')
+ Region.create(:name => '江西省')
+ Region.create(:name => '山东省')
+ Region.create(:name => '河南省')
+ Region.create(:name => '湖北省')
+ Region.create(:name => '湖南省')
+ Region.create(:name => '广东省')
+ Region.create(:name => '广西壮族自治区')
+ Region.create(:name => '海南省')
+ Region.create(:name => '重庆市')
+ Region.create(:name => '四川省')
+ Region.create(:name => '贵州省')
+ Region.create(:name => '云南省')
+ Region.create(:name => '西藏自治区')
+ Region.create(:name => '陕西省')
+ Region.create(:name => '甘肃省')
+ Region.create(:name => '青海省')
+ Region.create(:name => '宁夏回族自治区')
+ Region.create(:name => '新疆维吾尔自治区')
+ end
+
+ def self.down
+ drop_table :regions
+ end
+end
@@ -0,0 +1,4 @@
+class City < ActiveRecord::Base
+ has_many :districts
+ belongs_to :region
+end
@@ -0,0 +1,3 @@
+class District < ActiveRecord::Base
+ belongs_to :city
+end
@@ -0,0 +1,3 @@
+class Region < ActiveRecord::Base
+ has_many :cities
+end
View
@@ -1 +1,21 @@
# Install hook code here
+require 'fileutils'
+
+puts "** Installing chinese_regions Plugin"
+
+puts "** Installing chinese_regions models"
+model_src_path = File.join(RAILS_ROOT, '/vendor/plugins/chinese_regions/generators/models/')
+model_dest_path = File.join(RAILS_ROOT, '/app/models/')
+['region.rb', 'city.rb', 'district.rb'].each do |file|
+ FileUtils.cp(File.join(model_src_path, file), File.join(model_dest_path, file))
+end
+
+puts "** Installing chinese_regions migrations"
+migration_src_path = File.join(RAILS_ROOT, '/vendor/plugins/chinese_regions/generators/migrations/')
+migration_dest_path = File.join(RAILS_ROOT, '/db/migrate/')
+['create_regions.rb', 'create_cities.rb', 'create_districts.rb'].each do |file|
+ FileUtils.cp(File.join(migration_src_path, file), File.join(migration_dest_path, Time.new.getutc.strftime("%Y%m%d%H%M%S") + "_" + file))
+ sleep 1
+end
+
+puts "** Successfully installed chinese_regions Plugin"

0 comments on commit 039ecaa

Please sign in to comment.