之前有看到了 guanMac 的文章 http://my.eoe.cn/guanmac/archive/6105.html 但后来翻 guides 时候,发现其实有更 easy 的方法来实现。
3.9 Request-Based Constraints You can also constrain a route based on any method on the Request object that returns a String. You specify a request-based constraint the same way that you specify a segment constraint:
get 'photos', constraints: {subdomain: 'admin'}
You can also specify constraints in a block form:
namespace :admin do
constraints subdomain: 'admin' do
resources :photos
end
end