7

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.

yell
  • 113
  • 1
  • 6

3 Answers3

3

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"
yell
  • 113
  • 1
  • 6
  • Thanks for this. Did you ever figure out the optimal configuration? I have exactly the same problem where the asset URLs are fine but the links are not prefixed by the sub-app. I am using nginx with Puma. – danebez Jun 05 '15 at 11:17
  • I tried several configurations based on the given solutions. I found two minimal solutions: either just config.relative_url_root = "/App", or config.action_controller.relative_url_root = "/App". The file config.ru has to be modified... . Using environment variables, I could just get to pages, but assets (images, js, and css) where not handled... – user1251840 Sep 23 '16 at 09:24
2

In Rails 4.2, I had the same need and resolved modifying some configuration files. Routes.rb:

Rails.application.routes.draw do
  scope :mytm do
     ....
  end 
end 

This do not require any modification to the application.

Furthermore, you have to reconfigure the asset pipeline, in /config/initializers/assets.rb:

  Rails.application.config.assets.prefix = "/app/asset"
  ....
sbos61
  • 554
  • 2
  • 9
0

I'm not entirely sure if I understand what you're trying to do, but I think what you're describing is essentially namespacing all of your controllers under "/App" or something like that. This would be in your routes.rb file:

namespace "App" do

  # Put your resources here, as however you defined them before, e.g.:  
  resources :users, :decks, :cards, :revs, :sessions

end
Rob Wise
  • 4,930
  • 3
  • 26
  • 31
  • 1
    I tried this before; doing this results in `App/users is not a supported controller` – yell Jan 04 '15 at 02:22