ruby-on-railsrelative-url

Rails relative_url doesnt adjust links


After failed attempts with Passenger (see my other question), I managed to get rails running via a reverse proxy in a subfolder. I added the lines

config.relative_url_root = "/App"
config.action_controller.relative_url_root = "/App"

to my environment. Now I can access my rails project under www.mySite.com/App. The problem is that the links /paths dont add the prefix "/App". So a link to "users" looks like www.mySite.com/users instead of www.mySite.com/App/users. How can I change this?

At least according to http://edgeguides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root I did everything correct.


Solution

  • I got it working by adjusting my reverse proxy and my rails config as follows. This is my corresponding apache file:

    <VirtualHost *:80>
    DocumentRoot /path/to/App/public
    ProxyPass /App http://127.0.0.1:9292/App
    ProxyPassReverse /App http://127.0.0.1:9292/App
    </VirtualHost>
    

    My config.ru looks like this:

    require ::File.expand_path('../config/environment',  __FILE__)
    map '/App' do
      run Rails.application
    end
    

    The mentioned environments variables are set in /config/environment.rb. I am not sure if they are still needed:

    config.relative_url_root = "/App"
    config.action_controller.relative_url_root = "/App"
    ENV['RAILS_RELATIVE_URL_ROOT']  = "/App"
    ENV['ROOT_URL']  = "/App"