ruby-on-rails – 强制子域和删除子域
发布时间:2020-12-17 03:27:21 所属栏目:百科 来源:网络整理
导读:我正在编写一个将使用basecamp样式子域的应用程序( See post). 应用程序的某些部分应始终位于子域中,而部分应永远不应位于子域中.例如,“主页”页面永远不应位于子域中,但博客和帖子资源应该始终存在.请注意,我不知道子域名,因为每个帐户都有一个子域名. 我
我正在编写一个将使用basecamp样式子域的应用程序(
See post).
应用程序的某些部分应始终位于子域中,而部分应永远不应位于子域中.例如,“主页”页面永远不应位于子域中,但博客和帖子资源应该始终存在.请注意,我不知道子域名,因为每个帐户都有一个子域名. 我设置了这样的路线(例子).它运行良好,因为它匹配路线,但我很难强迫我的应用程序链接到正确的位置. MyApp::Application.routes.draw do # these should all route to mysubdomain.myapp.com # Clicking on a post from myapp.com/categories/12 should take you to mysubdomain.myapp.com/posts/14 constraints(Subdomain) do resources :blogs { resources :posts } end # these should all route to myapp.com (clicking on one of these links from mysubdomain.myapp.com should go to myapp.com/categories/12) constraints(NoSubDomain) do resources :categories end end 问题是,一旦我在子域中,所有到其他页面(类别等)的链接都包含子域.我不确定最好解决这个问题.非常感谢你的帮助. 解决方法
看起来可以通过覆盖url_for方法来包含:subdomain选项来完成.
请参阅清理代码以更改RailsCasts#221的子域部分. Railscasts:http://railscasts.com/episodes/221-subdomains-in-rails-3 ASCIIcasts:http://asciicasts.com/episodes/221-subdomains-in-rails-3 然后你可以这样做: <p><%= link_to "All Blogs",root_url(:subdomain => false) %></p> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- swift常用的宏
- 笔记5:转:VB.NET(2005)图形的处理(bitmap,byte(),
- ruby-on-rails – ror – 在has_many和belongs_to的两端包含
- iPhone应用程序在从Xcode启动时崩溃,但不是从iPhone启动
- 微信开发调试,当通过其他工具(不经过手机微信,直接填写好
- rest service 测试过程中的问题
- ruby-on-rails – 添加用户名来设计rails 4
- Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Ca
- OSC 第 110 期高手问答 —— OC & Swift 运行时特性
- create-react-app project 报错问题