2011-09-10 84 views
2

我目前得到的錯誤:的Rails 3.1的子域控制器的基於路由

No route matches [GET] "/tenant_admin" 

我用的是一樣的東西:
http://example.com/accounts/1/tenant_admin

但我現在經過帳戶ID作爲子域;
http://AccountName.example.com/

是否有可能使URL的工作是這樣的:
http://AccountName.example.com/tenant_admin


Routes.rb 

    get "log_out" => "sessions#destroy", :as => "log_out" 
    get "log_in" => "sessions#new", :as => "log_in" 
    get "sign_up" => "users#new", :as => "sign_up" 


    resources :users 
    resources :sessions 
    resources :password_resets 

    resources :accounts do 
    resources :tenant_admin 
    end 

    constraints(Subdomain) do 
    match '/' => 'accounts#show' 
    end 

    root :to => "welcome#index" 
+1

你可以做到。要看看如何在rails 3.x中做到這一點,而不使用任何額外的插件檢出這個railscasts插曲http://railscasts.com/episodes/221-subdomains-in-rails-3?autoplay=true –

+0

謝謝。我有點工作。我真正的問題是路由第三種類型的網址。 –

回答

4

你必須把resources :accountsconstraints(Subdomain)下租客路線。我不建議使用複製和粘貼,而是使用lambda代替。

tenant_routes = lambda do 
    resources :tenant_admin 
end 

resources :accounts do 
    tenant_routes.call 
end 

constraints(Subdomain) do 
    tenant_routes.call 
end