0

Rails versions: 3.2
I have an existed PHP site and I would like to add new features in it with Rails.

The final gole is to migrate the entire site to rails, therefore I choose to use mod_proxy to integrate rails by a sub path: /ror

Here's my mod_proxy setting:

<Proxy *>
  Order deny,allow
  Allow from all
</Proxy>
ProxyPass /ror http://localhost:3000/
ProxyPassReverse /ror http://localhost:3000/

The problem is, when I tying to use url helper, rails gives the relative path which is wrong.

<%= url_for(:action => 'index', :controller => 'travels' %>

Gives

/travels/

And the correct result will be

/ror/travels/

The idea of url helper and other helper with relative url is good. I intent to use them. How do I set the correct root path for rails to use in helper?

Jason Lu
  • 31
  • 3

1 Answers1

0

if you are using rails 4, here is what you may add before proxy declaration:

ProxyRequests Off
ProxyPreserveHost On

And add retry=0 to allow rails server to restart

ProxyPass /ror http://localhost:3000/ror retry=0

in config.ru

map "/ror" do
run Rails.application
end

map "/" do
run Rails.application
end

in config/application.rb
add this line:

config.action_controller.relative_url_root = "/ror"

Notice that this will direct all url from:

http://domain.com/ror to http://localhost:3000/ror

remember to use link_to or root_url to get uri with baseuri /ror

Community
  • 1
  • 1
james tan
  • 51
  • 3