From c298adda7c2ddd61bbc47a1e9b29497e98e55fa9 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Thu, 14 Jan 2016 20:37:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=90=E5=9F=9F=E5=90=8D=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/subdomain.rb | 9 +++++++++ config/routes.rb | 7 ++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 config/initializers/subdomain.rb diff --git a/config/initializers/subdomain.rb b/config/initializers/subdomain.rb new file mode 100644 index 000000000..b868e7e0b --- /dev/null +++ b/config/initializers/subdomain.rb @@ -0,0 +1,9 @@ +class Subdomain + + def matches?(request) + o = Organization.where(domain: request.subdomain).first + request.path_parameters[:id] = o.id if o + !o.nil? + end + +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 133203a8b..7d746f9e0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,12 +72,9 @@ RedmineApp::Application.routes.draw do end end - Organization.where("domain is not null").each do |org| - get '/', to: 'organizations#show', defaults: { id: org.id }, constraints: {subdomain: org.domain} + constraints(Subdomain.new) do + get '/', to: 'organizations#show' end - get '/', to: 'organizations#show', defaults: { id: 5 }, constraints: {subdomain: 'micros'} - get '/', to: 'organizations#show', defaults: { id: 23 }, constraints: {subdomain: 'nubot'} - get '/', to: 'organizations#show', defaults: { id: 1 }, constraints: {subdomain: 'team'} resources :org_member do member do