问题描述
我网站上的用户可以拥有子域.例如,他们的页面 url 是
A user on my site can have a subdomain. So for example, their page url is
name.example.com
登录的用户可以查看更多用户信息,因此在用户的显示页面上,我有一个使用以下代码生成的链接:
Logged in users are able to view more user information so on the user's show page, I have a link that is generated with the following code:
user_url(@user, :subdomain => false)
此链接应生成以下网址(其中@user 的 ID 为 19)
This link should generate the following url (where @user has an ID of 19)
example.com/users/19
当我将鼠标悬停在链接上时,一切看起来都不错(即,在浏览器窗口的底部,Safari 和 FF 都正确显示了链接.)
When I hover over the link, all looks good (i.e., in the bottom of the browser window, both Safari and FF show the link correctly.)
问题是当我点击链接时,该网站引发了 404,网址是:
Problem is when I click the link, the site raises a 404 and the url is:
example.com/users/19
有谁知道 com 和用户之间的斜线发生了什么,我该如何恢复?
Anyone know what happened to the slash between com and users and how do I get it back?
顺便说一句,Rails 3.2 和一切都在开发中.此问题仅在生产中出现.
BTW, Rails 3.2 and everything works in development. This issue only arises in production.
推荐答案
第一个建议是使用 path helper 而不是 user helper,但是编辑它,因为我认为这没有帮助.
First suggestion was using path helper instead of user helper, but editing that as I don't think that helps.
您是否尝试过 root_url(:host => request.domain) 而不是您的方法来丢失子域?我从这里得到的:https://github.com/rails/rails/issues/2025
Have you tried root_url(:host => request.domain) to lose the subdomain, instead of your approach? I got that from here: https://github.com/rails/rails/issues/2025
这篇关于子域中的 Rails url 助手 - 删除子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!