yell
yell

Reputation: 113

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.

Upvotes: 7

Views: 5306

Answers (3)

sbos61
sbos61

Reputation: 564

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"
  ....

Upvotes: 2

yell
yell

Reputation: 113

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"

Upvotes: 3

Rob Wise
Rob Wise

Reputation: 5120

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

Upvotes: 0

Related Questions