rails 二级域名

xiaoxiao2021-02-28  27

目前用ruby on rails 做开发,碰到一个子域名问题: www.trustie.net/organizations/:id 映射到 subdomain.trustie.net 代码实现: 在routes.rb中配置:   constraints(Subdomain.new) do     get '/', to: 'organizations#show'   end Subdomain定义在configs/initializers中, class Subdomain   def matches?(request)     o = Organization.where(domain: request.subdomain).first     request.path_parameters[:id] = o.id if o     !o.nil?   end end 就可以实现动态子域名定制
转载请注明原文地址: https://www.6miu.com/read-2150371.html

最新回复(0)