ruby on rails 实现动态子域名进入相关店铺页面
2018-03-26 09:58
701 查看
目前用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
就可以实现动态子域名定制
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
就可以实现动态子域名定制
相关文章推荐
- Ruby on rails开发从头来(windows)(三)-实现页面间的跳转
- Ruby on Rails,通过建立页面导航链接实现页面跳转
- Ruby on rails开发从头来(windows)(三)-实现页面间的跳转(修正原版错误)
- Ruby on rails开发从头来(windows)(三)-实现页面间的跳转
- Ruby on rails开发从头来(windows)(三)-实现页面间的跳转
- Ruby on Rails,利用View Templates生成动态页面
- ruby on rails 如何实现动态方法调用?
- Ruby on rails开发从头来(windows)(三)-实现页面间的跳转
- Ruby on Rails,通过建立页面导航链接实现页面跳转
- 在ruby on rails中实现验证码
- Ruby on rails开发从头来(四十八)- ActiveRecord基础(动态查询)
- Ruby on Rails Tutorial 学习笔记 --第三章 基本静态的页面
- 通过js实现编辑功能ruby on rails 弹出层
- 举例理解Ruby on Rails的页面缓存机制
- ruby on rails 注册登录模块的简单实现
- Ruby on Rails,通过页面链接向Controller中传递参数,附赠调试技巧
- RAILS 4 ON RUBY的AJAX实现过程
- Ruby on rails开发从头来(windows)(六)-美化你的列表页面(修正原版错误)
- 基本身份验证(HTTP Basic Authentication)及在Ruby on Rails下的实现
- 通过js实现编辑功能ruby on rails 弹出层