开发者

Rails 3.1 subdomain based controller routing

开发者 https://www.devze.com 2023-04-04 04:05 出处:网络
I\'m currently getting the error: No route matches [GET] \"/tenant_admin\" I was using something like: http://example.com/accounts/1/tenant_admin

I'm currently getting the error:

No route matches [GET] "/tenant_admin"

I was using something like:

http://example.com/accounts/1/tenant_admin

but I'm now passing the account id as a subdomain;

http://AccountName.example.com/

Is it possible to make the url work like this:

http://AccountName.example.com/ten开发者_开发技巧ant_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"


You have to put your tenant routes under resources :accounts and constraints(Subdomain). I don't recommend using copy and paste but a lambda instead.

tenant_routes = lambda do
  resources :tenant_admin
end

resources :accounts do
  tenant_routes.call
end

constraints(Subdomain) do
  tenant_routes.call
end
0

精彩评论

暂无评论...
验证码 换一张
取 消