Alex Rivera | Logout

How to deploy Rails 3.1 app in a subdirectory

Asked 2011-09-03T20:35:37.853
9

How do I configure a Rails 3.1 application to run under a specific directory such as "/r"?

I tried in config.ru:

map '/r' do
    run Debtor::Application
end

but that just returned "Not Found: /r"

To get it to work I had to enclose all routes in a scope:

scope '/r' do 
    #routes
end

and to add the following line to config/applcation.rb

config.assets.prefix = "/r/assets"

and to move my jquery ui css files from /stylesheets to /r/stylesheets.

this seems too complicated. isn't there an easier way? and why isn't my config.ru setting working?

my use case is to have a rails powered ajax backend for a wordpress server.

Edit
Report

1 Answer

3

Here’s how to deploy a Rails 3.1 app to a subdirectory in Apache, replacing config.action_controller.relative_url_root which no longer exists.

In config/routes.rb:

scope 'my_subdir' do
  # all resources and routes go here
end

In your Apache configuration file:

Alias /my_subdir /var/www/my_subdir/public
<Location /my_subdir>
  SetEnv RAILS_RELATIVE_URL_ROOT "/my_subdir"
  PassengerAppRoot /var/www/my_subdir
</Location>

And it should work, including automatically pointing all your assets to /my_subdir.

answered 2011-09-09T23:16:18.630

Your Answer