I am porting a 2.x rails app to rails3; we\'ll call it foo-app. Foo-app is one section of a larger rails app and lives at main_rails_app.com/foo-app. Previously we just set
I feel like I must be over-complicating this and/or missing something, but this issue has been frustrating me for a while now, and here are my notes.
There are two separate issues with two points each for dynamic and static routes:
One way to solve all four points:
relative_root portion
/ like developmentRAILS_RELATIVE_URL_ROOT environment variable
ScriptName middleware below (modify it to use the value from the environment)
users_path# config.ru
map '/relative_root' do
run Myapp::Application
end
SCRIPT_NAME rack/urlmap.rb:62SCRIPT_NAME to url_for options metal/url_for.rb:41So that covers URLs generated by the url helpers, e.g. given UserController, users_path will be prefixed by the relative url root.
# config.ru
class ScriptName
def initialize(app, name)
@app = app
@name = name
end
def call(env)
env['SCRIPT_NAME'] += @name
@app.call(env)
end
end
use ScriptName, '/relative_root'
run Rails.application
app.config.relative_url_root configuration.rb:41config.action_controller.relative_url_root/relative_root (rizzah's answer)# config/routes.rb
Myapp::Application.routes.draw do
scope '/relative_root' do
...
end
end
/relative_root/images/logo.png will result in "no route matches" exceptions. This may not be an issue if nginx is serving static assets anyway.Given a config like this:
upstream myapp {
server localhost:3000;
}
server {
...
location /relative_root {
proxy_pass http://myapp/;
}
}
Nginx will strip out the /relative_root, and the Rails app will not see it. If you need the Rails app so see it, one way is to change the proxy_pass line:
...
proxy_pass http://myapp/relative_root/;
...