diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index bae0232a5..2a4bcf9c8 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -30,7 +30,8 @@ class OrgSubfieldsController < ApplicationController if params[:id] @organization = Organization.find(params[:id]) else - @organization = Organization.where("domain=?",request.subdomain).first + domain = Secdomain.where("subname=?", request.subdomain).first + @organization = Organization.find(domain.pid) end @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+ "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+ diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 6e2da311f..f225e7f50 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -139,7 +139,7 @@ class OrganizationsController < ApplicationController end def check_uniq_domain - @is_exist = (Organization.where("domain=?", params[:org_domain]).count > 0) + @is_exist = (Secdomain.where("subname=?",params[:org_domain]).count > 0) end def find_organization @@ -322,7 +322,12 @@ class OrganizationsController < ApplicationController def agree_apply_subdomain @organization = Organization.find(params[:organization_id]) OrgMessage.find(params[:act_id]).update_attribute(:viewed, 1) - @organization.update_attribute(:domain, params[:org_domain]) + if Secdomain.where("pid=? and sub_type=2",@organization.id).count > 0 + domain = Secdomain.where("pid=? and sub_type=2",params[:organization_id]).first + Secdomain.update(domain.id, :subname => params[:org_domain]) + else + Secdomain.create(:sub_type => 2, :pid => params[:organization_id], :subname => params[:org_domain]) + end if OrgMessage.where("message_type='AgreeApplySubdomain' and organization_id=#{@organization.id} and content=?",params[:org_domain]).count == 0 OrgMessage.create(:user_id => params[:user_id], :organization_id => @organization.id, :message_type => 'AgreeApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain]) end diff --git a/app/views/layouts/base_org.html.erb b/app/views/layouts/base_org.html.erb index 81c6e82a5..d20d637ee 100644 --- a/app/views/layouts/base_org.html.erb +++ b/app/views/layouts/base_org.html.erb @@ -46,12 +46,12 @@ <% else %> - - + + <% end %> - <% end %>
<%= org.description %>
创建者:<%= link_to User.find(org.creator_id), user_path(org.creator_id), :class => 'linkGrey2', :target => '_blank' %>
diff --git a/config/initializers/subdomain.rb b/config/initializers/subdomain.rb index f813a24a0..b66059de5 100644 --- a/config/initializers/subdomain.rb +++ b/config/initializers/subdomain.rb @@ -9,7 +9,7 @@ class Subdomain o = ::Secdomain.where(subname: request.subdomain).first if(@opt[:sub]) - if o && o.sub_type == 2 && request.path_parameters[:sub_dir_name] == 'news' + if o && o.sub_type == 2 request.path_parameters[:id] = o.pid request.path_parameters[:controller] = 'org_subfields' request.path_parameters[:action] = 'show' diff --git a/db/migrate/20160223021012_add_index_to_secdomain.rb b/db/migrate/20160223021012_add_index_to_secdomain.rb new file mode 100644 index 000000000..928dfdbab --- /dev/null +++ b/db/migrate/20160223021012_add_index_to_secdomain.rb @@ -0,0 +1,5 @@ +class AddIndexToSecdomain < ActiveRecord::Migration + def change + add_index(:secdomains, :subname, unique: true) + end +end diff --git a/db/migrate/20160223021227_move_domain_to_secdomain.rb b/db/migrate/20160223021227_move_domain_to_secdomain.rb new file mode 100644 index 000000000..0c78f0ac6 --- /dev/null +++ b/db/migrate/20160223021227_move_domain_to_secdomain.rb @@ -0,0 +1,14 @@ +class MoveDomainToSecdomain < ActiveRecord::Migration + def up + Secdomain.transaction do + #将组织中的子域名迁移至secdomains表 + Organization.where("domain is not null").each do |org| + Secdomain.create(sub_type: 2, subname: org.domain, pid: org.id) + end + #remove_column :organizations, :domain + end + end + + def down + end +end diff --git a/db/migrate/20160223031843_remove_domain_from_organizations.rb b/db/migrate/20160223031843_remove_domain_from_organizations.rb new file mode 100644 index 000000000..d49ab3964 --- /dev/null +++ b/db/migrate/20160223031843_remove_domain_from_organizations.rb @@ -0,0 +1,8 @@ +class RemoveDomainFromOrganizations < ActiveRecord::Migration + def up + remove_column :organizations, :domain + end + + def down + end +end