Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

ruby - Rails app in a subdirectory

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.

A quick scan of google led me to using: ActionController::AbstractRequest.relative_url_root = "/rails_app"

However, it seems this has been removed in the latest Rails. Any ideas as to the equivalent in Rails 2.3.8?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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'

However, I've found that this only prefixes paths to assets. URL paths created by url helpers doesn't respect this setting.

Turns out, there's a bug related to this: https://github.com/rails/rails/issues/5122

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

Maybe try namespacing instead:
http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing

This answer might also be helpful:
Configuring a Rails 4 app for production in a subdirectory under Apache


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...