您的位置:首页 > 编程语言 > Ruby

ruby on rails 实现动态子域名进入相关店铺页面

2018-03-26 09:58 585 查看
目前用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
就可以实现动态子域名定制
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: