Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy Rails 3.1 app in a subdirectory

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.

like image 812
Peder Avatar asked Sep 03 '11 20:09

Peder


2 Answers

are you running under passenger?

Then RailsBaseURI is probably what you want.

https://www.phusionpassenger.com/library/deploy/apache/deploy/ruby/#deploying-an-app-to-a-sub-uri

If not running under passenger, please update your question to show what you are deployed under.

like image 69
Doon Avatar answered Oct 01 '22 14:10

Doon


What worked for me was creating the symbolic link for the sub-uri (/info) to the 'public' folder of the application (setup under another user on my server, /home/otheruser/current/public).

ln -s /home/myapp/current/public /home/mysite/public_html/info

Then I inserted this configuration inside of the VirtualHost entry for the site:

Alias /info /home/myapp/current/public
<Location /info>
  PassengerAppRoot /home/myapp/current
  RackEnv production
  RackBaseURI /info
</Location>

No scoped routes, no asset prefix configuration.

like image 35
af_jason Avatar answered Oct 01 '22 14:10

af_jason