diff --git a/app/models/secdomain.rb b/app/models/secdomain.rb new file mode 100644 index 000000000..4d0abe5db --- /dev/null +++ b/app/models/secdomain.rb @@ -0,0 +1,18 @@ +class Secdomain < ActiveRecord::Base + attr_accessible :pid, :subname, :sub_type, :desc + + validates_presence_of :subname, :sub_type + validates_uniqueness_of :subname + + def controller + return 'organizations' if sub_type == 2 + return 'users' if sub_type == 3 + nil + end + + def action + return 'show' if sub_type == 2 + return 'show' if sub_type == 3 + nil + end +end diff --git a/db/migrate/20160202034530_create_secdomains.rb b/db/migrate/20160202034530_create_secdomains.rb new file mode 100644 index 000000000..49650d073 --- /dev/null +++ b/db/migrate/20160202034530_create_secdomains.rb @@ -0,0 +1,28 @@ +class CreateSecdomains < ActiveRecord::Migration + def change + create_table :secdomains do |t| + t.integer :sub_type #1.系统预留 2.Organization 3.users + t.string :subname #子域名 + t.integer :pid, default: 0 #参数id + t.string :desc + + t.timestamps + end + + #系统保留 + Secdomain.create(sub_type: 1, subname: 'gitlab') + Secdomain.create(sub_type: 1, subname: 'wechat') + Secdomain.create(sub_type: 1, subname: 'judge') + + #organization + Secdomain.create(sub_type: 2, subname: 'micros', pid: 5) + Secdomain.create(sub_type: 2, subname: 'nubot', pid: 23) + Secdomain.create(sub_type: 2, subname: 'team', pid: 1) + + #users + Secdomain.create(sub_type: 3, subname: 'whm', pid: 7) + Secdomain.create(sub_type: 3, subname: 'yg', pid: 5) + Secdomain.create(sub_type: 3, subname: 'wt', pid: 11) + + end +end