子域名路由实现

chenlw_dev
guange 10 years ago
parent d935532f8d
commit c298adda7c

@ -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

@ -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

Loading…
Cancel
Save