我无法让我的路由约束在 Rails 4 中工作。这是我的路由文件:
Catapult::Application.routes.draw do
constraints Subdomain do
resources :contacts do
member do
get 'delete'
end
end
end
end
这是子域约束:
class Subdomain
def self.matches?(request)
p request.subdomains.first # This never appears in the logs
request.subdomains.first !~ /www|catapultcentral|customercube|lvh/
end
end
如上面的代码中所述,p
语句的输出从未出现在日志中,并且似乎从未应用约束。这是的输出rake routes
:
Prefix Verb URI Pattern Controller#Action
delete_contact GET /contacts/:id/delete(.:format) contacts#delete
contacts GET /contacts(.:format) contacts#index
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
contact GET /contacts/:id(.:format) contacts#show
PATCH /contacts/:id(.:format) contacts#update
PUT /contacts/:id(.:format) contacts#update
DELETE /contacts/:id(.:format) contacts#destroy
约束也不会出现在输出中......
请问我做错了什么?