子目录中的 Rails 应用程序
尝试在子目录中设置 Rails 应用程序.我的服务器是切诺基.我有一个基本网址:www.nonsense.com,这是一个 wordpress 博客,我想在 www.nonsense.com/rails_app 中设置一个 rails 应用程序.
Trying to set up a Rails app in a subdirectory. My server is Cherokee. I have a base url of: www.nonsense.com, which is a wordpress blog, and I wish to set up a rails app in, www.nonsense.com/rails_app.
谷歌的快速扫描让我使用:ActionController::AbstractRequest.relative_url_root = "/rails_app"
A quick scan of google led me to using: ActionController::AbstractRequest.relative_url_root = "/rails_app"
然而,这似乎在最新的 Rails 中被删除了.关于 Rails 2.3.8 中的等价物的任何想法?
However, it seems this has been removed in the latest Rails. Any ideas as to the equivalent in Rails 2.3.8?
对于 Rails 4/5,您可以在 application.rb
或 production.rb
中设置:
For Rails 4/5, you can set this in application.rb
or production.rb
:
config.relative_url_root = "/app1"
或者简单地设置这个环境变量:
Or simply set this environment variable:
RAILS_RELATIVE_URL_ROOT='/app1'
但是,我发现这只是在资产路径前加上前缀.由 url 助手创建的 URL 路径不遵守此设置.
However, I've found that this only prefixes paths to assets. URL paths created by url helpers doesn't respect this setting.
事实证明,有一个与此相关的错误:https://github.com/rails/rails/issues/5122
Turns out, there's a bug related to this: https://github.com/rails/rails/issues/5122
这应该已经修复了它,但我没有发现情况是这样:https://github.com/rails/rails/pull/18775/files
This is supposed to have fixed it, but I've not found that to be the case: https://github.com/rails/rails/pull/18775/files
此功能的文档并不清楚它应该如何工作:
The documentation for this feature isn't very clear on how exactly it's supposed to work:
http://edgeguides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root
也许可以试试命名空间:
http://guides.rubyonrails.org/routing.html#controller-命名空间和路由
Maybe try namespacing instead:
http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing
这个答案也可能有帮助:
配置用于生产的 Rails 4 应用程序Apache下的一个子目录
This answer might also be helpful:
Configuring a Rails 4 app for production in a subdirectory under Apache