Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 658
mebFace Avatar asked Jul 28 '10 16:07

mebFace


1 Answers

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

like image 50
Sean Moubry Avatar answered Oct 24 '22 14:10

Sean Moubry